Community Documentation

Clean URLs with Apache 2 on Debian Lenny w/Backports Drupal 6.16 (and Squeeze)

Last updated December 13, 2010. Created by rclemley on April 25, 2010.
Edited by ghoti. Log in to edit this page.

These instructions enable you to configure apache2 to support Drupal's Clean URLs for a default lenny backports installation of drupal 6 (currently drupal6 6.16-1~bpo50+1). Therefore, these instructions should also cleanly work for Debian Squeeze (currently in testing). The default installation serves drupal 6 as http://localhost/drupal6/. These instructions may work for earlier versions of Drupal 6 on Lenny and possibly Etch and possibly Ubuntu versions. Please comment if you have success with these other versions.

For information about Debian Backports, visit http://www.backports.org/.

How To

To enable Clean URLs in the defalt configuration, first, ensure that the apache2 "Rewrite Module" is enabled:

sudo a2enmod rewrite

Next, edit one and only one file, /etc/apache2/conf.d/drupal6.conf, and make these mods within the <Directory> block (careful, this file is a symlink: /etc/apache2/conf.d/drupal6.conf -> /etc/drupal/6/apache.conf):

  1. Change AllowOverride to None
  2. Add the Rewrite Module directive RewriteBase, setting it to /drupal6
  3. Include the default drupal 6 .httaccess file, /usr/share/drupal6/.htaccess.

The modified /etc/apache2/conf.d/drupal6.conf file will now look like this (changes in bold-italic):

Alias /drupal6 /usr/share/drupal6

<Directory /usr/share/drupal6/>
    Options +FollowSymLinks
#   AllowOverride All
    AllowOverride None
    order allow,deny
    allow from all
    <IfModule mod_rewrite.c>
        RewriteBase /drupal6
    </IfModule>
    Include /usr/share/drupal6/.htaccess
</Directory>

After changing the file, restart apache2 with the command:

sudo /etc/init.d/apache2 restart

Then navigate to your drupal adminstrative site configuration Clean URLs page, ensure that the system is correctly configured, and then enable Clean URLs and test.

Discussion

Changing AllowOveride to None and including the .htaccess file within the <Directory> means that Apache2 will only load the .htaccess file once (at startup).

I recommend against the practice of adding more AllowOveride All directives because this will cause apache2 to read the .htaccess file on every web request, instead of just once on startup.

The RewriteBase /drupal6 directive appears as a comment in the /usr/share/drupal6/.htaccess file, but I recommend putting the directive in the conf.d/drupal6.conf file because why change more config files than necessary?

Comments

It works for my drupal sites

Thanks so much for this info. It was the only one that worked! Thank You!

Thanks, it works.

Thanks very much, it work for my Drupal installation under Debian Squeeze.

Regards,
emeck

Page status

No known problems

Log in to edit this page

About this page

Drupal version
Drupal 6.x
Audience
Site administrators
Drupal’s online documentation is © 2000-2013 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.