Knowledgebase
Knowledgebase: Cloud Server
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

Overview:

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.

 

Prerequisites:

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.
If you wish to become more familiar with .htaccess files and their usage NetTuts has provided an excellent introduction.

 

Step-by-Step:

Step 1. For this tutorial, we will use Tom's Tools .htaccess-generator to first create an .htaccess entry to allow IP addresses.

  • Visit Tom's htaccess generator
  • Enter the IP address(es) you would like to allow access (Your IP address is displayed below in red)
  • Change the dropdown box to allow these IP address and ban everyone else
  • Click Generate Code


Example .htaccess code:

# ALLOW USER BY IP

 order deny,allow
 deny from all
 allow from 1.2.3.4

			

 

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

  • Paste the code within the .htaccess file
  • Upload via FTP

 

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.

(29 vote(s))
Helpful
Not helpful

Comments (0)