Sunday, May 4, 2008

IP based restriction in Apache

We can restrict the access to any particular URL and its sub urls by modifying apache's Config. file

For example : if we have to restrict admin section of our site to be browsable only by few specified IP then in apache's Config. file we just have to add

<\Location /admin>
Order Allow,Deny
Allow from 191.16.25.62
<\/Location>
( Please remove the '\' before open and close Location tag's )


This is only allow requests coming from 191.16.25.62 , requests from any other IP will get

Forbidden

You don't have permission to access /admin on this server.

This restriction also applies to the sub-urls like admin/user_list etc....

Suppose we have to provide access to more than one IP, then we just have to provide the different IP's separated by a space between them.

Like

Allow from 191.16.25.62 191.16.25.63 ..........

The same can be applied for rejecting a request from a specified IP


Order Allow,Deny
Deny from 191.16.25.62