Thursday 31 May 2007

Apache Restricting using htaccess

Have you ever made a site you only want a few people to access? Perhaps you have a competitor who keeps viewing your website?

Well, there's several easy ways in apache to do this using the htaccess file and here they are;

Restrict Access by IP Address


Ok, there are several commands to remember when restricting by IP address. The first is that everything needs to go in limit tags;

<limit></limit>

Depending on the information you need you can either specify POST or GET or both as an option of the limit tag (e.g. <limit POST GET>). POST is used when getting user id's and GET is used to get information like hostnames and ip addresses.

The next useful commands are 'deny from' and 'allow from'. You can deny or allow from 'all' or from specific ip addresses or from hostnames e.g.

<limit GET>
deny from all
</limit>

This means no-one has access to this site when placed in the htaccess file.

<h2>Useful Examples</h2>

Allow only from a computer with an ip address of 192.168.1.10;

<limit GET>
deny from all
allow from 192.168.1.10
</limit>

Allow only from computers with an ip address in the range of 192.168.1.*

<limit GET>
deny from all
allow from 192.168.1
</limit>

Allow everyone apart from computers with hostname google.co.uk or ipaddress of 192.168.1.10

<limit GET>
allow from all
deny from google.co.uk
deny from 192.168.1.10
</limit>



www.suffolk-web-design.co.uk/

No comments: