WordPress.org

Ready to get started?Download WordPress

Forums

Blocking spam with htaccess (1 post)

  1. Ate Up With Motor
    Member
    Posted 7 months ago #

    I've been looking at my 404 logs and some jackass has apparently been trying to do searches on my site with terms like "generic viagra" as part of the URL. Those results are returning a 404, which is obnoxious in part because it adds server load (I have a custom 404 page with a partial sitemap).

    I'd like to block queries that include certain strings anywhere in the query and have the server simply return 403 Forbidden instead of 404. It seems like I should be able to do that with mod_rewrite in the .htacesss file, but I'm having trouble getting it to work. (I'm not real good with regexes and the syntax of .htaccess commands is not very familiar.)

    Here's what I've got:

    # Block tiresome spam
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{QUERY_STRING} ^.*(viagra|cialis|levitra|nickname|generic|propecia).* [NC]
    RewriteRule ^(.*)$ - [F,L]
    </IfModule>

    However, I'm still getting queries with some of those terms in the 404 logs. Anyone know what I'm doing wrong?

Reply

You must log in to post.

About this Topic

  • RSS feed for this topic
  • Started 7 months ago by Ate Up With Motor
  • This topic is not resolved
  • WordPress version: 3.7.1