Thursday, August 30, 2007

Enabing mod_rewrite for Drupal 5.1 in Kubuntu

By default, Drupal have those annoying ?q= in the URL but you can disable them by configuring apache2.conf and enabling mod_rewrite. Why do we need to disable them? Search Engine Optimization.... the ?q= is the bane of SEO marketers and Search Engine bots sometimes skip sites with ?q= in the URL.

Enabling mod_rewrite
Issue the following command:

sudo a2enmod rewrite

That command will add the rewrite.load file to /etc/apache2/mods-enabled directory. To check if it's loaded, issue the command:

apache2ctl -M



Copy the Rewrite Engine
Append the following into your /etc/apache2/apache2.conf file.

 <Directory /var/www/>
   RewriteEngine on
   RewriteBase /
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
</Directory>



Restart Apache
Issue the following command:

sudo /etc/init.d/apache2 restart

Configure Drupal's Clean URL
Go to Administer > Site Configuration > Clean URLs
Click the Run the clean URL test link.



Success
If successful, the page below would show up, and would now allow you to Enable Clean URLs. Click the Save configuration button after you're done.



Don't forget the Path Module
Don't forget to enable the Path Module in Administer > Site Building > Modules
This will allow you to change the URL of a page.

Problems I encountered

  • The Clean URLs Handbook is too (and I mean too) generic. And I'll bet new Ubuntu users wouldn't understand what the hell that is.
  • The Option A in the handbook doesn't work. No matter what I do. I've tried re-reading the said handbook and re-configuring the apache2.conf but I still failed to make it work.

Blogged with Flock