University of Southern California

ITS Information Technology Services

The .htaccess File

A .htaccess (dot-htaccess) file contains directives (commands) executed by the server before it delivers files to a browser. Some of the most common uses for the .htaccess file include:

The filename begins with a dot (period) in order to signal the server that it contains server commands and is not meant to be served as a Web document.

Scope of the .htacess File

If you create a .htaccess file for one of your web directories, the effects from that file will be applied to all of the files in that directory and all subdirectories within that directory UNLESS you create a separate .htaccess file for that subdirectory. For example, if your main directory is called 'foo' and you have a .htaccess file that defines files with a '.htm' extension to be given the MIME type 'text/plain', but you have a subdirectory called 'bar' which you want files with a '.htm' extension to be given the MIME type 'text/html', you will need to create a seperate .htaccess file for the 'bar' directory.

The .htaccess file also overrides conflicting MIME type definitions in the server configuration file.

Common Problems

Two conditions can cause the web server to ignore all or part of a .htaccess file:
  1. The server cannot read the file.
    The .htaccess file must be world-readable to be effective. For further information please see documentation on setting file permissions.
  2. The server ignores the last command in a file.
    UNIX commands must end with a carriage return to signal end-of-line. Since many Macintosh and PC word processors do not automatically end a file with a carriage return, the server will ignore the last line in a file if it doesn't end in a return. An easy way to ensure that your last command ends with a return is to add another line with a UNIX comment character (#) to the end of your .htaccess file.

Last updated:
June 21, 2007

Web Publishing Documentation

The use of all USC computing resources is governed by the USC Computing Policies.