htaccess

Reduce Comment Spam With htaccess

Comments

Comment spam is a problem with many blogs, one of the biggest is spam bots crawling sites and automatically submitting comments to your site. The below code snippet will check the HTTP_REFERER on the wp-comments-post.php, it will make sure that you can only get to this page if you are on the current domain.

Below is a snippet you can use on your .htaccess to help reduce the amount of spam coming through on your comments page on your WordPress blog.

Just add the following into your htaccess file to reduce spammers.

<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteCond %{REQUEST_METHOD} POST 
RewriteCond %{REQUEST_URI} .wp-comments-post.php* 
RewriteCond %{HTTP_REFERER} !.*yourdomainname.* [OR] 
RewriteCond %{HTTP_USER_AGENT} ^$ 
RewriteRule (.*) ^http://%{REMOTE_ADDR}/$ [R=301,L] 
</IfModule>

This snippet will check the the URL coming to the wp-comments-post.php file is from your own domain.

Back to top ^

Comments

  1. SOFT SUNRISE says:

    i hv a custom site how can i block user not to spam with htacess

    1. Paul says:

      Adding the above code to your htaccess should help. If not then try this tutorial https://paulund.co.uk/no-comment-spam

Leave a Reply

Your email address will not be published. Required fields are marked *

Join Paulund

  • Access 100s of premium tutorials and downloadable content
  • Members content consists of premium WordPress plugins, CSS packages, jQuery packages, tutorial demo files and templates for 100s of web development tutorials
  • In-depth development tutorials
  • Priority tutorial requests
  • No ads

Join Paulund