How-to Enable Clean URL’s in Drupal 5

Oy vey, getting clean URL's to work in Drupal has been a bitch, but we finally got it and I'll share how to do it!

We have a Drupal site we just moved to the production server, which is on Media Temple. Media Temple has Apache's mod_rewrite enabled by default, which is really sweet.

(You NEED mod-rewrite in order to do clean URL's. If your server won't let you, move!)

For Drupal there are two things you need to do, the first of which is modifying the .htaccess file. Media Temple gives you some clues in this knowledgebase article, but it's not quite what we need for Drupal.

Create a file named '.htaccess' in the main Web directory where Drupal resides. F'rinstance, if your drupal site is at www.site.com/drupal, .htaccess should be at www.site.com/drupal/.htaccess. (More than likely it'll just need to be at www.site.com/.htaccess however.)

Add the following to .htaccess:

Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond\n%{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

Ok, then. Now open up your settings.php file. This is usually at /sites/default/settings.php. (Or it may be at /sites/all/settings.php). Crank that puppy open and at the very bottom add this line:

$conf['clean_url'] = 1;

Go to your admin area and enable clean URL's (it's at http://yoursite.com?q=admin/settings/clean-urls).

It's that easy! Of course, it took me over an hour to figure that out, and it shouldn't have been that difficult. That's why I'm sharing with you. I know, I know, I'm a nice guy, keep that praise coming.

All the best of luck with your clean URL-enabling and Drupal installs!

It seems to me that better

It seems to me that better solution is to enable clean urls form drupal's admin panel, than your "hardcoded" solution. From admin panel, you have option to make test for clean urls (is your web server configured properly for clean urls?) before you enable it. If you enable clean urls, but your web server isn't configured properly for clean urls, your drupal web site will be in the problem (links will not be functional)

Yes, that would be

Yes, that would be nice! However, that was the whole problem; the option to enable it in the admin area was greyed out. The problem was, in fact, getting the Web server enabled to run clean URL's. Once that was done, the option to enable it was 'open' in the admin panel.

There is a lionk on that

There is a lionk on that very same page called 'clean url test' Click it and the options will be selectable

Right, that may work for

Right, that may work for some cases, but in mine it did nothing. I would click it and go to a 404 error page, which (I think) indicates you don't have mod_rewrite enabled or set up properly. Hence, the needed .htaccess changes.

Drupal comes with an

Drupal comes with an .htaccess file with all this (and more) in. A common problem is missing it when uploading a site via ftp.

Weird ...I thought there was

Weird ...I thought there was supposed to be an .htaccess file in the main directory too, but I'm not seeing it. I just downloaded drupal 5.1, unpacked it, and did a listing (ls -l, to view hidden files) and it's not there. Perhaps this is supposed to get created during installation, and it never got copied over? After all, I usually create the Drupal install locally, then move it to a remote server.

It's ls -a not ls -l to view

It's ls -a not ls -l to view hidden files!

Thank you, sir, you are

Thank you, sir, you are correct! That would explain why I didn't see it! :-p

I tried following the

I tried following the instructions above, but had no luck. I kept getting an error. But the following method worked great (and it was simple). First, I created a 1-click drupal install on my MediaTemple server. This installs Drupal 4.7, (but that's okay, we are just going to create the .htaccess file). Once the 1-click install was complete, I went to the administration section, clicked the 'test clean urls' and was then able to turn clean url's on. I then created a new subdomain where I installed Drupal 5.3. (there was no .htaccess file created, so maybe this was the problem all along). I copied the .htaccess file from the drupal 4.7 directory to the drupal 5.3 directory. logged into the drupal 5 administration section, ran the 'test clean url' and it worked! I haven't run into any issues so far, so hopefully there aren't any computability issues with copying an .htaccess file created by an earlier version of drupal hopefully this helps some others.

I just installed Drupal 6.1

I just installed Drupal 6.1 and it seems that just adding the (mt) suggested Options +FollowSymLinks to the included .htaccess file above RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?q=$1 [L,QSA] was enough to pass the clean URL test for me.

Right, that may work for

Right, that may work for some cases, but in mine it did nothing.I would click it and go to a 404 error page, which (I think) indicates you don't have mod_rewrite enabled or set up properly. Hence, the needed .htaccess changes Chris Italian Translation