Home / Tutorials / htaccess – Allow or Restrict Website Access by IP or IP range or Country
restrict website

htaccess – Allow or Restrict Website Access by IP or IP range or Country

To secure our website, mostly we need to allow or restrict website access by IP or IP range or Country or countries either for security reason or even to disallow bots or humans to access our website. You can easily do this by restricting/allowing those IP or IP ranges in .htaccess file.

Restrict Website Access by IP

Write following lines in your .htaccess

Above lines will block access to your site from 123.0.0.5 IP address.

Now suppose you want to do converse if this, meaning you want to allow access to your site only from 123.0.0.5 IP then
you need to write following in your .htaccess file

To Block access from a certain IP range, you will write following in your htaccess file:

Above lines will disallow to access website from any IP from 123.0.0.0 to 123.0.0.255

To Allow access only from a certain IP range, you will write following in your htaccess file:

Above will allow access to your website from 10.10.11.1 to 10.10.11.25 IPs.

Restrict Website Access by Countries

In similar fashion, we can even allow/block any country or countries from accessing our website. For this the logic is same, we will allow/block all the possible IP ranges for that particular country or countries.

There are some 3rd party tools available which will generate .htaccess code for us and we will just paste that in our .htaccess. Some of the online generators are:

www.ip2location.com
incredibill.me
www.countryipblocks.net

 

 

About cmadmin

Web Developer & Designer | Android App Developer

Leave a Reply

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

Login


Username
Create an Account!
Password
Forgot Password? (close)

Sign Up


Username
Email
Password
Confirm Password
Want to Login? (close)

Forget Password?


Username or Email
(close)
%d bloggers like this:
SHARE
OR
SUBSCRIBE
To get latest new / tutorial / technology / development information subscribe with us.
ARE YOU READY? GET IT NOW!
Lets Get Updated with latest trends & tutorials!
Your Information will never be shared with any third party.
Ready for latest tutorials & tools !
OR SUBSCRIBE WITH