Drupal Clean URL's with IIS7

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=5018
Download 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/drupal

RewriteRule ^/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.

4 comments:

Anonymous said...

Hello,

First thank you for this post. I'm trying to enable Drupals 6 clean URLs on IIS7 using ISAPI IIRF Module, but I just couldn't do it. Is there a way to check if ISAPI module is actually running?

I created a Web Site under my IIS server (Drupal 6), so Drupal is not in Default Web Site. Could this be a problem? Where can I find IsapiRewrite4.ini? I renamed Drupals .htaccess file to IsapiRewrite4.ini, but it still doesn't work? Can you help me somehow? Where should I put this dll and ini file, if my Drupal installation is not in Default Web Site?

First Site of Drupal runns smoothly when I forced it to enable Clean URLs, but if I click on a link (let's say administer), I get this error:

HTTP Error 404.0 - Not Found
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.

Module IIS Web Core
Notification MapRequestHandler
Handler StaticFile
Error Code 0x80070002

Thank you for the answer!

Best wishes,
Marko

Anonymous said...

I successfully enabled Clean URLs on Drupal 6. I used IIS7 URL Rewrite module, and I imported rules from IIRF ISAPI Rewrite module (example for Drupal, which is included in the package).

After that, Clean URLs worked fine, but there was no CSS and no images. I noticed that if I enter full URL to CSS file, I get Sever Error, something about rewrite module. I just added another rule on the top of them all, so that if the wildcard *.* matches with entered URL (files), every mod rewrite rule isn't applied, and after that, Clean URLs are still working fine and also CSS and images are applied.

Best wishes,
Marko

Anonymous said...

locksnlatches.blogspot.com is very pleasant to read. The article is very professionally written. I enjoyed reading locksnlatches.blogspot.com. keep it that way.

Anonymous said...

Great blog as for me. I'd like to read a bit more about this matter. Thanx for sharing this information.
Sexy Lady
London escort