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.
The .htaccess and .htpasswd files work in a tree fashion. Assume you
set up your directories as follows.
mydir
mydir\subdir1
mydir\subdir2
mydir\subdir3\bottomdir
mydir\subdir4
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.
Additional Reading
- Htaccess file If you have direct access to the .htaccess file, then you are in luck. You can do some very cool things.
- Htaccess file - Protecting directories The most common usages of .htaccess is to restrict access to all of the files within a directory.
- Htaccess file - MIME types You can use .htaccess to define your own MIME types. What this means is you can associated file types with actions to be
performed.
- Htaccess file - Custom error pages You can use htaccess to define custom error pages to trap 404 and other error conditions.
- Htaccess file - Redirect You can redirect visitors to other pages using the redirect function of htaccess.
- Htaccess file - Deny Deny is especially useful to block out unwanted spiders and malicious visitors.
- Htaccess file - Rewrite Rewrite is a complex, but useful feature which can help you stop spam harvesters.
- Htaccess file - Redirect Worms Away Is your site running on an Apache server and is your log file being filled with useless errors from the recent
worm penetrations? Is your bandwidth being used to no good cause? Here's a solution which might help.
Unless otherwise noted, all photos and text is Copyright © Richard G Lowe, Jr.