HMC Homepage      CS Home

How to Create an .htaccess file

a guide to telling Apache what to do with your stuff

You can change how Apache handles your documents with an .htaccess file. Such a file is named .htaccess and affects the behavior in the directory it is located in as well all nested directories (which can override that .htaccess file with their own.) To create an .htaccess file:

  1. From the directory you wish to affect, type:

    %emacs .htaccess

    (Or use whichever editor you prefer.)

  2. Add the desired directives.

  3. Close and save the file.

  4. Type the following on the command line to allow apache to read the file:

    %chmod a+r .htaccess

  5. If you're unsure of what you're doing or just like to be thorough, open a web browser and make sure things do what they're supposed to.
Here are some things you can do with an .htaccess file:

Display directory trees

The apache configuration is such that directories without index files will not display the directory tree structure -- you'll just get a forbidden.

For example, you want to be able to see the contents http://www.cs.hmc.edu/~mwaring/test even though you do not have an index.html file in ~mwaring/public_html/test.

  1. Add the line

    Options +Indexes

    to the .htaccess file in that directory (create one if necessary.) If there is already an Options line simply add

    +Indexes

    onto the end of it.

If you want to explicitly state that apache should not display directry trees, add Options -Indexes instead.

Display .pl files as text

By default, .pl files are executed as cgi scripts by Apache. If you want them to be displayed as text instead:

  1. Add the following line to the .htacces file (create one if necessary) in the directory they reside in:

    RemoveHandler .pl

Enable Server Side Includes

For information on SSI see the Server Side Includes qref. To activate them in your directory, do the following:

  1. Add the following line to the .htaccess file (create one if necessary):

    or add

    FollowSymLinks IncludesNOEXEC

    to the existing Options line if there is one.

  2. Also add the following lines:

    AddType text/html .html
    AddHandler server-parsed .html



Copyright (c) HMC Computer Science Department. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with the no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is included in the section entitled ``GNU Free Documentation License.''

HMC Computer Science Department
Contact Information
Last Modified Thursday, 28-Mar-2002 13:43:57 PST