On Unix servers, the
.htaccess file is a way to customize the environment of your web site. The most well known customization is to restrict access of a directory to one or more people, but there are actually many other things that you can do.
- Protecting your directories
- Set MIME types
- Custom error pages
- Denying access to specified IP addresses and domains
- Redirecting pages
.htpasswd files work in a tree fashion. Assume you set up your directories as follows.
If you put a
.htaccess file in “mydir” it will apply on all lower directories, unless overridden by a
.htaccess file. In this example, you could put a
.htaccess file in “subdir4”. This file will apply only to “subdir4” and no others. If you put one in “subdir3” it would also apply to the lower level directory “bottomdir”.
Additionally, understand that these files apply to entire directories, not individual files.