---
title: "Rewrite rules fail on subdirectories, subdomains, or addon domains"
date: "2014-12-08"
category: "web-content"
slug: "rewrite-rules-fail-subdirectories-subdomains-addon-domains"
---

## Overview

Rewrite rules remap URLs to other locations or resources on your site. These rules are placed in [[htaccess-guide]] files. A common snippet looks like:

```
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
```

When this snippet is placed anywhere other than the [[where-is-site-content-served-from]] of the primary domain, the rewrite rules will fail and produce an error (see [[accessing-page-views-and-error-messages]]).

## Cause

Rewrite rules modify URLs relative to the `DocumentRoot` defined in the web server configuration. Each site has a single `DocumentRoot` set to `/var/www/html`. Additional domains, subdomains, and resources under `/var/www/html` are subject to filesystem remaps outside this root. Without `RewriteBase`, the rewrite engine cannot resolve paths correctly.

## Solution

Add `RewriteBase /` immediately after `RewriteEngine On` in your [[htaccess-guide]].

If the `.htaccess` file resides in a subdirectory that also appears in the URL path (e.g. `http://example.com/mysubsite`), use that path instead: `RewriteBase /mysubsite`.

The corrected snippet:

```
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
```
