Friday, July 29, 2011

htaccess allow from


htaccess allow from gives you the ability to allow (or deny) specific IP’s or domain names from a directory on your server. To do this the syntax is quite simple. UsingVIM or nano open up the .htaccess file in the directory that you want to restrict access to. You need to add the following:
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
This allows access from your local host and the IP address you specify. Using .htaccess you can also allow by host name. This is useful if you wish to allow or deny a friend access to a directory. (note: it will also work if you have them in your hosts file)
Order Deny,Allow
Deny from all
Allow from LinuxBlog
Allow from .thelinuxblog.com
Using htaccess to allow from your LAN is also pretty easy. You use your CIDR address (ip/subnet) to do this try something like this (changing to match your LAN):
Order Deny,Allow
Deny from all
Allow from 192.168.1.1/24
I run into htaccess allow problems a lot, and hope that this will clear the air up for me. htaccess can be very handy if you do not want to keep turning your firewall on and off, but do not want your directories wide open. Just remember, if you want to stop everyone except those you choose to access your apache web directories, use htaccess allow from!