apache Mod Rewrite

Stopping the spam after moving house

A few weeks ago I moved this blog to this new location but left a 301 redirect on all URLs on the old site. That has worked great to direct traffic here but unfortunately it has also redirected all the spam attempts on my old site to here too. Thankfully they’re not much of an issue because the POST information is lost but it’s annoying seeing them appear in the logs.

Thanks to the wonders of mod_rewrite it’s possible to stop those guys before they hit any PHP script. My blog was originally at and of course, the new site is There are two way of stopping those requests:

  • On the new server, add the following lines to the .htaccess of the virtual host:

RewriteCond %{HTTP_REFERER} ^http://blogs\.linux\.ie/ [NC]
RewriteRule ^wp-comments-post.php – [F]

  • Or, on the old server add this to the .htaccess there:

RewriteRule ^xeer/wp-comments-post.php – [F]

The latter rule is the preferred method and I haven’t seen any request come through since I added it in!

If you’re interested, here are the simple rules I use to redirect every url of my old blog to this site:

RewriteRule ^xeer/images/(.*)$1 [R=301,L]
RewriteRule ^xeer/(.*)$1 [R=301,L]

Adapt to suit your own environment.