Clean URLs don't work? Check your .htaccess file!

Here are some of the most common reasons why your clean URLs may not be working (assuming you're using a normal Linux/Apache hosting environment).

1. Your .htaccess file didn't get uploaded at all.

Check if the .htaccess file was actually uploaded. It should be in the directory where you uploaded Drupal (for example: /public_html/drupal/)

If the .htaccess file is missing, you need to upload it. If you accidentally deleted this file, just download Drupal again, and copy the new .htaccess file.

Make sure the file is only called .htaccess and not htaccess.txt or anything else. The .period .at .the .beginning is required.

2. Your .htaccess file is corrupt.

The .htaccess file is very fussy, and only works if things are in a certain order. If you've tried to add password protection or to block image hotlinking (especially if you used cPanel or some other software to set that up), you've probably corrupted the file. The simple solution is to delete your corrupted .htaccess file, then upload the standard version that comes with Drupal.

3. Your site is in a subdirectory, but you didn't set RewriteBase

If your site URL looks like this:

http://example.com/~jsmith1/drupal/

Then you need to set RewriteBase! Find the section in your .htaccess file that looks like this:

  # Modify the RewriteBase if you are using Drupal in a subdirectory and
  # the rewrite rules are not working properly.
  #RewriteBase /drupal

And change the last line, like this:

  RewriteBase /~jsmith1/drupal/

Make sure you remove the # symbol in front of RewriteBase, otherwise this will not work.

If you move your site later on, this line will need to be changed again. For example, if you later move it to: http://your-site-here.com/ then update the line to RewriteBase / (or just comment it out with a # in front).

4. Pager and other query strings don't work

Make sure you have not modified the Apache rewrite rule. The default RewriteRule is:

RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

What this rule does is rewrite a path like example.com/node into example.com/index.php?q=node

However, you'd normally then expect that path like example.com/node?page=1 would be re-written into into example.com/index.php?q=node?page=1 which would fail since both separators are ?.

However, the rewrite rule has additional flags. The 'L' flag is irrelevant, but 'QSA' makes the difference. What it does is to preserve any existing arguments after the rewrite, thereby changing the second '?' in this scenario into '&'.

Worked for me on 1and1

joe@groups.drup... - July 3, 2008 - 00:28

Under no circumstances could I get clean URLs working. The site I'm hosting on is 1and1. After checking that "RewriteEngine on" was in my .htaccess file, I couldn't figure it out. Then I played around with "RewriteBase". At first I tried the full physical path to the site root directory, but that broke the entire site and made it inaccessible. This example makes it seem that if you leave RewriteBase uncommented, that it defaults to a value of root, "/". However, when that's exactly what I set it to ("RewriteBase /"), clean URLs finally worked.

 
 

Drupal is a registered trademark of Dries Buytaert.