The default unclean URLs that Drupal provides with question marks lurking around, could be annoying. But it does offer an option to have clean URLs. I couldn’t find a neat tutorial to do this and this was not of great help either. So, let us see how to get this done.
Step 1
Check whether the rewrite module for your apache is enabled. Assuming you have an apache2 installation, you can do this by
ls /etc/apache2/mods-enabled/
If you don’t find rewrite.load, it means that the rewrite module is not enabled. Drupal’s clean URLs feature requires this module to be enabled. If you have a Debian based machine,
sudo a2enmod
Which module would you like to enable?
Your choices are: actions alias asis auth_basic auth_digest authn_alias authn_anon authn_dbd authn_dbm authn_default authn_file authnz_ldap authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache cern_meta cgid cgi charset_lite dav_fs dav dav_lock dbd deflate dir disk_cache dump_io env expires ext_filter file_cache filter headers ident imagemap include info ldap log_forensic mem_cache mime mime_magic negotiation php5 proxy_ajp proxy_balancer proxy_connect proxy_ftp proxy_http proxy rewrite setenvif speling ssl status suexec unique_id userdir usertrack version vhost_alias
Module name?rewrite
Module rewrite installed; run /etc/init.d/apache2 force-reload to enable.
This can also be done like this (say for a non-Debian based OS):
cd /etc/apache2/mods-enabled
sudo ln -s ../mods-available/rewrite.load rewrite.load
There! We have enabled the rewrite module for apache.
Step 2
We have to edit /etc/apache2/sites-available/default. Look out for the following lines.
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Change AllowOverride None to AllowOverride All. Save the File.
Step 3
Make sure that the .htaccess file under your Drupal installation folder has the following lines
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
</IfModule>
Step 4
Restart the apache server
sudo /etc/init.d/apache2 restart
Step 5
Go to your Drupal administration page for clean URLs and enable them.
May 14, 2008 at 11:13 pm
Cool da! One of the most educative posts I have come across… continue posting such articles…
May 15, 2008 at 10:34 am
Thanks
Had to hunt lots of places to get the correct combination
May 19, 2008 at 4:50 am
I do appreciate your write up here but I am sadly lost after trying this in my terninal:
ls /etc/apache2/mods-enabled
I am using Mac OS X Leopard.
I am using MAMP ad my local testing server. I have the Prefs set to PHP 4.
Could I persuade you to write up something for me to learn how to fix my inability to create clean urls?
Any help would be greatly appreciated and I can give you more details about my settings.
Regards,
Josh
May 19, 2008 at 10:24 am
[...] Friendly URL’s with Drupal. I ran into a need to delve into some serious command line stuff. SO I am looking for a [...]
May 19, 2008 at 5:29 pm
Personally, I have never worked with a Mac. And in India (where I live), a Mac is an extremely rare thing to find
. Hence, I have absolutely no idea about apache on a Mac. Anyhow, what’s your apache version? If its not apache2 then, /etc/apache2 directory will not exist. For apache 1.X, there are other ways to enable modules.
Basically, for getting clean URLs to work with Drupal, you need the ‘mod_rewrite’ module enabled. This module is by default disabled in a standard apache installation (though I have heard that the latest releases of MAMP come with mod_rewrite enabled). Perhaps you can try this out.
http://joshuaink2006.johnoxton.co.uk/blog/332/setting-up-an-os-x-development-server-by-an-idiot-
September 1, 2008 at 12:58 pm
Hello!,
February 7, 2009 at 4:42 pm
Great explanation!!!
April 22, 2009 at 12:23 pm
If you want to see a reader’s feedback
, I rate this post for four from five. Decent info, but I just have to go to that damn google to find the missed parts. Thank you, anyway!
May 28, 2009 at 10:46 am
Thanks! Worked like a charm!
June 13, 2009 at 8:30 pm
Thanks, Prasanna!
I’ve been pulling my hair in the last two hours trying to get clean URLs working.
To me, the key is Step 2:
Changing AllowOverride to All in “/etc/apache2/sites-available/default”.
When I was a Fedora user, I fiddled with directives in http.conf, so I thought in Ubuntu I should add this in apache2.conf but nothing in .htaccess was picked up. Now I know it was overwritten by the one in sites-available/default!
October 20, 2009 at 5:37 pm
it works..
October 25, 2009 at 3:24 am
WOW… I have looked at tons of sites and none have worked. Thank you very much for this.
October 27, 2009 at 2:06 am
Fantastic solution. Most other’s failed to accomplish this.
November 1, 2009 at 12:03 pm
No other site seems to mention
Change AllowOverride None to AllowOverride All.
Thank you
November 11, 2009 at 12:39 pm
I have saved this page. the best i have ever seen for clean urls for drupal and zend framework