IIS7 URL Rewrite: Importing IIS Mod-rewrite rules (or Apache mod_rewrite rules)

This article assumes the following:
  • You recently upgraded/moved your website to one of our plans hosted on a Windows 2008/IIS7 server.
  • You had been using IIS Mod-rewrite (or Apache mod_rewrite) rules in an .htaccess file to either redirect or rewrite your URLs.
IIS7 includes its own rewrite engine, called IIS7 URL Rewrite, that allows you to import your Mod-rewrite rules.  This article will walk you through the steps to accomplish this.
1.  Connect to your site via IIS Manager.  For instructions on how to connect with IIS Manager, see our article on the subject.
2.  Double-click on the URL Rewrite icon.
2.  Click "Import Rules..."
3. Copy and paste your Mod-rewrite rules onto the "Rewrite rules" field.

In this example, we'll be importing four rules -- two redirect rules and two rewrite rules, as follows:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example1.com [NC]
RewriteRule ^(.*)$ http://www.example1.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^example2.com [NC]
RewriteRule ^(.*)$ http://www.example2.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} www.example1.com
RewriteCond %{REQUEST_URI} !example1-directory/
RewriteRule ^(.*)$ example1-directory/$1 [L]
RewriteCond %{HTTP_HOST} www.example2.com
RewriteCond %{REQUEST_URI} !example2-directory/
RewriteRule ^(.*)$ example2-directory/$1 [L]
4. After clicking "Import," you'll see the Converted Rules below.  The green check-mark symbols indicate that the rules and conditions were successfully converted.
5.  Click "Apply" to apply the converted rule(s) to your site.
6.  Click "Back to Rules."
7.  You'll now see your imported rules listed under the URL Rewrite module in IIS Manager.

**Note that importing or creating URL rewrite rules in IIS Manager will add the rules into your web.config file.  As such, URL rewrite rules can be created directly into this file instead of creating them through the URL rewrite tool in IIS Manager.  If you don't have a web.config file on your site, one will be created automatically once you apply the rules.

Add Feedback