---
title: ".htaccess Guide"
date: "2014-11-09"
category: "web-content"
slug: "htaccess-guide"
---

## Overview

An `.htaccess` file contains directives that the web server applies before serving a page. These directives can [[changing-php-settings]], deny access, change the displayed page, or redirect requests to another URL.

A directive consists of a name and value, such as `DirectoryOptions +Indexes` or `php_flag display_errors on`.

## Directive Precedence

Before a request is processed, the server looks for a `.htaccess` file in the directory from which [[where-is-site-content-served-from]]. Directives in that file are applied first. The server then walks down through each parent directory until it reaches `/var/www`, applying directives from any `.htaccess` files found along the way.

> ### Example
>
> A page is served from `/var/www/mydomain.com`. The server finds `.htaccess` files at `/var/www/mydomain.com/.htaccess` and `/var/www/.htaccess`. First, rules in `/var/www/mydomain.com/.htaccess` are applied. Then, rules in `/var/www/.htaccess` are applied, overriding any conflicting rules from the subdirectory.
>
> **Note:** An `.htaccess` file placed under `/var/www` applies global configuration to every subdomain and domain located under `/var/www`. Be careful with addon domain locations.

## Creating an .htaccess File

Create a plain-text file named `.htaccess` and upload it to the [[where-is-site-content-served-from]] for the subdomain or domain you want to configure.

> You can also create an empty file [[creating-empty-files]] under **Files** > **File Manager**, then click the **Edit** action in the _Actions_ column to make changes from your browser.

## Writing Directives

Each directive occupies a single line. Examples of **valid** directives:

- `Options +Indexes`
- `RewriteCond %{HTTPS} ^ON$`
- `php_value error_reporting 99999`
- `PassengerEnabled On`

Examples of **invalid** directives:

- `Options`: Missing option values.
- `php_value error_reporting display_errors on`: Extraneous PHP [[changing-php-settings]].
- `RewriteCond %{HTTPS} ^ON$ RewriteRule ^(.*)$ https://mydomain.com/$1 [R,L]`: Each directive (`RewriteCond`, `RewriteRule`) must be on its own line.
- `PassengerEnabled yes`: `yes` is not an accepted value for `PassengerEnabled`.

## Handling Errors

If a directive is entered incorrectly, the site will display an _Internal Server Error_. Check [[accessing-page-views-and-error-messages]] for details on which directive was rejected and why.

## Common Directives

| Directive | Description | Example | Documentation |
|-----------|-------------|---------|---------------|
| `php_value` | Sets PHP runtime configuration | `php_value upload_max_filesize 32M` | [[changing-php-settings]] |
| `RewriteBase` | Anchors rewrite rules to the current directory | `RewriteBase /` | [Apache mod\_rewrite](http://httpd.apache.org/docs/2.2/rewrite/) |
| `Options` | Sets directory-specific options | `Options +Indexes` | [Apache core](http://httpd.apache.org/docs/current/mod/core.html#options) |
| `PassengerEnabled` | Enables Rails, Node.js, and Python autoloading | `PassengerEnabled On` | [Phusion Documentation](https://www.phusionpassenger.com/documentation/Users%20guide%20Apache.html#PassengerEnabled) |
