Skip Navigation
IT Connect
Connecting You to Information Technology at the UW

 

Introduction to .htaccess Files

IT Connect > Web > Publishing > .htaccess Files

This article provides an overview of .htaccess files. It explains what they are and how to create them. This article does not cover individual server directives used within .htaccess files.

About .htaccess Files

You can control the way the Web server responds to requests to your files by creating a .htaccess file in your Web directory or one of its subdirectories. A .htaccess file contains one or more server directives--small commands known by the server--that tell the server how to behave. For example, you can turn on password protection by using a .htaccess file.

Here are some specific properties to know about .htaccess files:

Creating .htaccess Files

Use a text editor such as Pico, Notepad, or SimpleText to create and modify .htaccess files. These editors specialize in plain text files.

Creating .htaccess Files Using Pico

If you want an easy way to create .htaccess files, try Pico. For example, to create a .htaccess file in your top-level Web directory:

  1. StepsActions
  2. Log into your web development server using a terminal emulator. If you're not sure how to do this, click here for instructions.

  3. At the prompt, enter the following command to change directories to your Web directory:

    cd public_html
  4. At the prompt, enter the following command to create a .htaccess file in the current working directory:

    pico .htaccess
  5. Use Pico to add the directives you want to your .htaccess file.

  6. Save and close the file using Pico. (Click for instructions on how to use pico).

You can find more instructions on how to use pico, as well as screenshots, here.

If you need help with Unix commands like these, see Getting Started With Unix.

Creating .htaccess Files on a Desktop Computer

To create a .htaccess file on your desktop computer use Notepad (Windows) or SimpleText (Macintosh). If you use a word processing program to create your .htaccess files be sure to save them as ASCII or plain text.

When you move a .htaccess file from your desktop computer to your Web directory remember to transfer it in text mode. Again, this helps preserve the plain text characteristic so important to .htaccess files.

Examples

Here is a one line .htaccess file used to redirect "404 Not Found" responses to a specific Web page:

ErrorDocument 404 /webdemo/404.html

Here is a more elaborate .htaccess file that associates .dot files to a specific MIME type and turns on basic password protection:

AddType application/vnd.msword dot
AuthType Basic
AuthUserFile .htpasswd
AuthName "Town of Bedrock"
require user fred