Commanding Chaos for Coworking, Open Source and Creative Communities

How I got my mod_rewrite to play nice with Apache 2 and Drupal

Sat, 09/16/2006 - 20:51 -- rprice

I have been installing Drupal sites like crazy recently, and one thing that really helps a Drupal site thrive is the Clean URLs feature. Clean URLs and smart permalinks and all sorts of things require Apache's wonderful mod_rewrite to be active. This isn't very hard, but it is if you don't know what you're doing.

This HowTo assumes that you have control over your entire server. If you don't, you need to contact your hosting support, or whichever geeky cousin you are getting your hosting from.

Here are three easy steps to enable search-engine-friendly URLs:

  1. Enable mod_rewrite in your /etc/httpd/conf/httpd.conf
    Notice: Screwing up this file will break your Apache server, so before you proceed, make sure you make a copy of your .conf file:
    ? cp httpd.conf httpd.conf.bak

    Then check for this line near the top of your file. It will be just after some comments referring to DSO, and a whole bunch of LoadModule statements.
    #
    # Dynamic Shared Object (DSO) Support
    #
    ...
    LoadModule rewrite_module modules/mod_rewrite.so
  2. Allow .htaccess files to override universal rules.
    This is the meat of this tutorial. Local directories need to be able to override the defaults and add their own RewriteRules. You put this in your file where you are setting up options for your root web directory. For my specific configuration, I had to put it in the first (/) one and not the next (/var/www/html) one. I tried them both.
    #
    # Each directory to which Apache has access can be configured with respect
    # to which services and features are allowed and/or disabled in that
    # directory (and its subdirectories).
    #
    # First, we configure the "default" to be a very restrictive set of
    # features.
    #
    Options FollowSymLinks
    AllowOverride All
  3. Don't forget to restart Apache!
    You need to restart Apache so it will read in the new logs and restart all the processes. Every single change you make to the .conf file means you need to restart Apache. The changes won't apply otherwise. On my system, this was a simple matter of entering the following command:
    ? apachectl -k graceful
    This is the "nice" way of shutting down and restarting Apache.
  4. Set your RewriteBase directory in your .htaccess file (maybe)
    If you're running multiple installs of Drupal on the same domain like me, you may also need to make a change in your .htaccess file in your base Drupal directory.If your install base is www.example.com/portal, you will need to find this line:
    #RewriteBase /drupal
    ...and change it so it reads:
    RewriteBase /portal

That's it! Once you've done this, navigate to your admin page, like http://www.example.com/admin/settings/clean-urls and check the radio button for "Enabled". If you did something wrong, the page won't load, and you'll know something went wrong.

Hope this helps! You can get more detailed information at drupal>>node/84496

The steps in this HowTo should also help if you are installing another piece of web software like Menalto Gallery 2, Wordpress, or Mambo/Joomla.

Categories: 
Tags: 

Commenting on this Blog post is closed.

Comments

Submitted by Ramon (not verified) on

I was trying to get it to work but was missing the "AllowOverride All" directive. Your post pointed that out. Thanks.