The .htaccess File
The .htaccess File
Tutorials > General > The .htaccess File
The Grand Guide to .htaccess
The .htaccess file is a file that, when placed within a folder on a webserver, allows you to control the way in which the webserver will respond to requests. This is done by using text commands, called server directives, within the file.
Before you start messing around with .htaccess files, there are some things you should be aware of:
- .htaccess files must always be plain text files. A program like Notepad is a good plain text editor.
- .htaccess commands apply to the directory the .htaccess file is in as well as all of its subdirectories unless the subdirectory contains its own .htaccess file.
- Each line is counted as one command or server directive.
- Lines beginning with a hash (#) are ignored. This is useful for commenting your file.
- The .htaccess file must always be named ".htaccess"!
There are many things that a .htaccess file can be used for. The ones included in this tutorial are:
- Securing the .htaccess File
- Custom Error pages
- Directory Passwords
- Blocking IP Addresses and IP Ranges
- Custom Directory Index
- Page Redirects
- Prevent Directory Listing (browser displays a list of all the files in a directory)
- Prevent Hot Linking (other sites using your files and your bandwidth)
- Adding MIME Types (file extensions)
- Online .htpasswd Generator