Using Drupal with Microsoft URL Rewrite Module for IIS 7

Categories:

It seems that only two years ago there was very limited choice when looking for a URL Manipulation tool for IIS, especially ones that can easily be adapted to work with mod_rewrite rules which is the only rewrite engine most PHP applications support. These days however there are several URL manipulation tools for IIS that support the Apache .htaccess/mod_rewrite syntax including the new URL Rewrite Module for IIS 7 from Microsoft. In this guide we'll look at just how easy it is to use this new module from Microsoft with the very popular PHP based Drupal CMS.

There only real prerequisites for using the Microsoft URL Rewrite Module is that you are using IIS 7, other than than you just need the actual Rewrite module which can be downloaded here.

Once you have the URL Rewrite module installed, the next step is to open the IIS Manager and browse to your Drupal website. With this site selected you should now be presented with a pane similar to below with a series of icons. Double click the URL Rewrite Module icon to continue.

Select the URL Rewrite Module

You'll now enter the URL Rewrite module settings. All we'll be doing for this task is using the import function, so click on the import rules link at the top right hand corner as shown below.

URL Rewrite administration screen

Next step is to select the mod_rewrite .htaccess file to import. To do this click on the browse button on the right hand side of the configuration file field.

Import Rules

Select your Drupal .htaccess file and then click the import button to import your rules as shown below.

Import .htaccess file

Once the .htaccess file is imported click the apply link in the top right hand corner of the screen, and you'll be returned to the main URL Rewrite module screen. From here all you need to do is rename the module to something more descriptive (e.g. Drupal) and make sure the rule is enabled from the context menu using the right mouse button.

Rename and enable rule

The final two steps you'll need to do is modify the request filtering in IIS so that functions like multiple word search strings work properly without giving you a 404 error, and to manually force Drupal to use Clean URL's as when using Microsoft's URL Rewrite module the REQUEST_URI variable is not supported as it is when using ISAPI Rewrite 3 from Helicontech.

To modify the request filter in IIS 7 open you ApplicationHost.config file and search for the following;

<requestFiltering

Then add this before the closing ">" character;

allowDoubleEscaping="true"

Save this, and your IIS config is complete.

Next, open your Drupal settings.php file and place the following code on a new line.

$conf['clean_url'] = 1; // 1 enables, 0 clears clean_url

Once you save this you should be all set to use Drupal's clean URL feature on IIS 7 using the new Microsoft URL Rewrite module. Any comments or feedback on the article, please feel free to post a comment below. If you'd like any specific support for your environment, then please post a new thread in the forums.

Average rating
(8 votes)

Comments

Anonymous's picture

Will it Work for IIS 6 ?

does this steps apply to IIS 6 also ?

Brashquido's picture

Microsoft URL Rewrite Module

Unfortunately the Microsoft URL Rewrite Module supports IIS 7 only. Have a look at Helicon's ISAPI Rewrite 3 for IIS 6.

----------------
Dominic Ryan
5 x Microsoft IIS MVP, MCSE, MCSA
IIS Aid owner/webmaster