How to Allow access only for IP range using htaccess (security tutorial)

Hello and welcome to this new development security tutorial for beginners, today we're doing to learn how to block access to a specific folder on your web-server and allow access to to a range of ip including your ip using the .htaccess directive, for example this is a must for PHPMyadmin folder or your website admin panel, this security step is very important and a must to protect your server DB and sensitive folders.

The idea is to block access from all IPs, exept the range for yours, basically you cannot allow a range of IPs on the .htaccess using the "allow from", but you can emulate it with multiple CIDR networks IPs format.


Bellow is a .htaccess example to allow access only to IP range from 10.10.10.0 to 10.10.10.255, to specific folder

Order Deny,Allow
Deny from All

# Allow only for range 10.10.10.0 to 10.10.10.255 (the 24 in CIDR mean 255)
Allow from 10.10.10.0/24



Change the red ip address with your ip range, and copy the above lines to a .htaccess on the root of the folder you want to protect, to check your ip just write "my ip" on google search.
 

More examples:
# To Allow all ips from 0.0.0.0 - 0.255.255.255.255 by fixing the first number.
Allow from 0.0.0.0/8


# Another one : 1.2.0.0 - 1.2.1.255
Allow from 1.2.0.0/23


# Allow small range : 1.2.3.0 - 1.2.3.3
Allow from 1.2.3.0/30




Thanks, and if you have any question leave a comment.

If you like this article, please share it on facebook, tweet it and +1 it to spread it :) !
How to Allow access only for IP range using htaccess (security tutorial) How to Allow access only for IP range using htaccess (security tutorial) Reviewed by Mhr on 15:40 Rating: 5

No comments

No Backlinks please, Comments are under moderation !