WordPress.org

Forums

Blocking spam with htaccess (1 post)

  1. Ate Up With Motor
    Member
    Posted 1 year 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?

Topic Closed

This topic has been closed to new replies.

About this Topic

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