Sometimes certain IP addresses trying to bring your website down and spammer make spam comments to advertise products or service. The best you can do to block them is to ban their IP address. For WordPress site you can use .htaccess file and some plugins. In this post i will show you how to stop spam comments and block IP, IP range or multiple IP to access your wordpress website.

Block spam comments:

WordPress has a option to ban or blacklist keywords and IP. For that go to the admin panel:

Settings > Discussions > Comment Blacklist

Enter one keyword or IP address per line to black or blacklist all spammers to keep them away from your blog comments area. But keep in your mind that most of the spammer use dynamic IP address allcation provide by ISP. So if you ban any spammer by its IP, they may get a differnt IP address from its ISP and start again spamming on your blog.

Prevent accessing wp-comments-post.php :
Most spammers attack your site form “wp-comments-post.php”, at the same time you prevent extra load on your server.

Paste this code into your .htaccess file.
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]

// Embed this code in your site using
//

This method will stop spam comments from spambots. But can’t stop human’s spam comments. Use WordPress Akismet plugin to block them.

Block IP address Using .htaccess file:
We will block IP address using .htaccess file. In wordpress you already have a .htaccess file.in the root directory. Suppose 123.168.0.1 IP address trying to bring your website down and randomly ping your site. To block this IP address from accessing your site, with the content below:

order allow,deny
deny from 123.168.0.1
allow from all
Block Multiple IP Address:
If you want to block multiple IP address write this code in .htaccess file.

order allow,deny
deny from 123.168.0.2
deny from 123.168.0.3
deny from 123.168.0.4
allow from all

Block an IP Network Range :
To block an IP Network Range use this code in .htaccess file.

order allow,deny
deny from 123.0.0
allow from all

Using Wild Card IP Ban :
If you need to block anyone at all with an IP that starts 123.123 -.

deny from 123.123.*.*

Using Plugin to ban IP :
Using WordPress Plugin if want to block some IP adresses permanently then you can use a plugin called WP-Ban. It will display a custom ban message when the banned IP, IP range, host name or referer url try to visit you blog. You can also exclude certain IPs from being banned. There will be statistics recorded on how many times they attempt to visit your blog. It allows wildcard matching too.

Hope from this tutorial You have learn how to stop spammer comments and block IP address . Using this method will reduce spam content on WordPress sites. So give yourself a break from spam and implement this user-friendly solution today.