¡Subscribe to our newsletter and receive our offers, news and discounts directly to your email!

Block access to your website by ipSometimes we find ourselves in the situation that we need certain users, regions, etc., to not be able to access our website. The most appropriate method to do this is to block access by IP.

This can help us to block IPs that are attacking us or users who are only trying to create spam within our page, among other utilities such as restricting the access of the administrator of our website only to the IP of our office.

Block IP by .htaccess

The easiest method that pays to do this is by blocking the IPs in the .htacces file (the server's configuration file). This file is very delicate, so it is normal when editing it that we find our website blank after editing it, so before making any changes we must make a backup copy of this file. 

Once we know the IP or set of IPs that we want to block so that they cannot access our website, we must place the following code in our .htaccess file, substituting the example IP for the one that we want to block.

 

order allow, deny

deny from 192.138.1.2

allow from all

 

If you want to block more IPs you just have to keep adding more IPs in the same way.

order allow, deny

deny from 192.138.1.2

deny from 192.148.1.1

allow from all

In this example you can block a set of IPs.

order allow, deny

deny from 192.138.1.

allow from all

Block IP using plugins

If we don't want to touch the .htaccess file because we don't dare or don't have the knowledge to do so, don't worry. We can use plugins that include this functionality and that will save us from having to touch this file ourselves. For example, iThemes Security brings this functionality included within the great repertoire of features that this plugin brings.

Solid Security – Password, Two Factor Authentication, and Brute Force Protection

But if we want a plugin that only brings this functionality, we can find plugins like IP ban, although it hasn't been updated for a couple of years, it still works perfectly with the current version:

IP Ban