Skip to content

Tutorial: .htaccess

Not allowing browsing of directories
If someone browses to a directory on your server that does not have an index.html file (or, whatever you set your default to) it will return a listing of all files in the directory. Obviously, this is not often a wanted event. Apache uses the Options directive. To disallow browsing of directories enter the following line in your .htaccess file.

Options -Indexes

Redirect Users
Say one day you decide that instead of naming your index file index.htm you want it called index.html. But, you have links all over the internet pointing to index.htm that you don’t want to break. Easy, just set up a Redirect.

The syntax for the Redirect directive is Redirect /oldfile.htm http:://www.site.com/newfile.htm. Notice that you need to enter the full URL to the new file.

Using a file other than index.html
When a directory is request from Apache, typically Apache looks for a default file in that directory to server. Usually this is the index.html file, although there is a list of files that can be server (index.htm, index.php, etc). If you decide you want your default to be somethingelse.html, you can use the DirectoryIndex directive.

DirectoryIndex somethingelse.html index.html index.htm index.php

Notice that there are several files listed after the directive. If the first file is not found, Apache will go through the list until it finds one. Failing that, the directory will be shown. See the notes on denying directory listings above.

Pages: 1 2 3 4 5

Published inProgramming

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *