How to restrict access to areas of my site with htaccess and ip blocking (linux sites only)
Posted by Somnath Kadam on 08 July 2013 02:45 PM
With .htaccess you can restrict access to sections of your website to verified IP addresses or IP ranges. This is particularly useful when you want to secure sections like "admin" or "configuration" on your website.
You should be comfortable with .htaccess files and have a Linux based web site with us. If you are using Windows based servers, this method will not work for you.
Step 1. For this tutorial, we will use Tom's Tools .htaccess-generator to first create an .htaccess entry to allow IP addresses.
# ALLOW USER BY IP order deny,allow deny from all allow from 220.127.116.11
Step 2. Copy the resulting code
Step 3. Create a new .htaccess file (or edit the existing one) in the folder you wish to secure
Step 4. Navigate to site and test
If everything is successful, only the IP addresses in the file will be able to view the website section the .htaccess folder was uploaded to. To double check this, you can use an Proxy web service to view your website from a different IP address.