Drupal can work with clean URL's (or URL write). The most talked about solution is using Helicon's ISAPI _Rewrite ISAPI add-in, which can be found here (
http://www.isapirewrite.com/) if you are interested. But here I want to show you how you can accomplish clean url's using a free alternative by Ionics called IIRF.
Perform the following steps to get clean URL's in Drupal 5.3 in IIS7:
1) Download Ionics Isapi Rewrite Filter
At the moment of writing this is the only quite reliable freeware URL rewriter for IIS. You can get it here:
http://www.codeplex.com/IIRF/Release/ProjectReleases.aspx?ReleaseId=5018Download the most recent "-bin.zip" version.
2) Install Ionics Isapi Rewrite Filter
- Extract IsapiRewrite4.dll to c:\inetpub\wwwroot (or your www root folder)
- Extract \examples\DrupalRules.ini to c:\inetpub\wwwroot (or your www root folder) as IsapiRewrite4.ini
If you haven't installed Drupal in the webroot, but, like me, in a subfolder, then you have to perform the following updates to DrupalRules.ini. I use
http://localhost/drupal, so I had to add
add "/drupal" to almost every RewriteRule. In stead of "/drupal" you can use any folder or level of subfolders that is necessary in your case, e.g. for
http://localhost/davy/dozy/tich you have to replace the bold "/drupal" string with "/davy/dozy/tich".
Here are some examples for each of the sections defined in DrupalRules.ini:
RewriteRule ^/misc/(.*)$ /misc/$1 [I,L]
RewriteRule ^/modules/tinymce/(.*)$ /modules/tinymce/$1 [I,L]
RewriteRule ^/cron\.php$ /cron.php [I,L]
RewriteRule /(.*)\?(.*)$ /index.php\?q=$1&$2 [I,L]
RewriteRule ^/(.*)$ /index.php?q=$1 [I,L]
become
RewriteRule ^
/drupal/misc/(.*)$
/drupal/misc/$1 [I,L]
RewriteRule ^
/drupal/modules/tinymce/(.*)$
/drupal/modules/tinymce/$1 [I,L]
RewriteRule ^
/drupal/cron\.php$
/drupal/cron.php [I,L]
RewriteRule
/drupal/(.*)\?(.*)$
/drupal/index.php\?q=$1&$2 [I,L]
RewriteRule ^
/drupal/(.*)$
/drupal/index.php?q=$1 [I,L]
The following RewriteRule has to be added to the first RewriteRule-section If you also use Gallery2:
RewriteRule ^/gallery2/(.*)$ /gallery2/$1 [I,L]
or if you use
http://localhost/drupalRewriteRule ^
/drupal/gallery2/(.*)$
/drupal/gallery2/$1 [I,L]
The RewriteRule function uses regular expressions to transform clean url's back to their non-clean equivalents.
3) Add ISAPI filter to IIS7
- Start IIS.msc
- Select Default Web Site (
not your virtual directory or application!)
- Double-click the ISAPI filters icon
- Add...
Filtername: IsapiRewrite4
Executable: C:\inetpub\wwwroot\IsapiRewrite4.dll
4) Set Drupal to use Clean URL's
- Start Drupal in your web browser
- Administer -> Clean URLs
- Click "Test for Clean URL's" (it is somewhat hidden in the paragraph text)
- Select enable
In my case, the enable check box was still greyed out. To set Clean URL's manually:
- Remove write-protection from the c:\inetpub\wwwroot\drupal\sites\default\settings.php file
- Edit the file and add:
# Force Clean urls
$conf['clean_url']=1;
- Set write-protection back.
Hopefully this quick and rudimentary instruction helps you setting up URL rewriting for you Drupal installation.