4. How
do I limit access to certain directories?
Access control is controlling
who can see what files in your account. You can
block or allow access to certain files or whole
directories of files in a number of ways, depending
on what you need. If you want to limit access with
the use of passwords, see the next section.
The main uses of access
control is to block or allow only people that are
browsing your pages from specific IP addresses,
subnets, host names and entire domains.
One reason you might want
to do this is if you have someone that won't stop
leaving you offensive comments in your guestbook.
You can find out the user's IP address or host name
by adding the right code to the guestbook script
and then use that to block the user from accessing
the guestbook form, or the entire site. Another
use would be to allow all people that are members
of a specific domain, for example, to have an AOL-only
site which only allows users of AOL to see it.
Simply define who can view
the site or who can't, as in the following example:
order allow,deny
allow from all
# block a specific IP address
deny from 123.123.123.123
# block a subnet, e.g.
123.234.56.0 through 123.234.56.255
deny from 123.234.56.
# block a specific host
name
deny from machine.domain.com
# block a given domain
name:
deny from .otherdomain.com
The first line tells the
server which order to evaluate the directives. For
"order allow,deny", any "deny" directives override
the "allow" directives. For "order deny,allow",
any "allow" directives override the "deny" directives.
NOTE: Do not put a space between the allow and deny
directives in the order statement.
The second line tells the
server that anyone can view the site.
The rest of the lines tell
the server who can't view the site.
In this case, anyone can
see the site, unless they are coming from the specified
addresses or domains in the "deny" directives.
You can hide the entire
directory with an .htaccess file that contains this:
order deny,allow
deny from all