IIS redirect to www

You need a simple way to redirect your website from domain.com to www.domain.com. This can be used to redirect from HTTP to HTTPS, as well.

Microsoft Internet Information Services (IIS) comes with URL Rewrite. It may or may not be installed. The below guide will help you to install and configre URL Rewrite.

Open IIS Manager and click on your site to check for URL being installed. You an install it through the Web Platform Installer (very useful to have), or just download it from the link above.iis-url-rewrite-1

Using the Installer, seach for URL Rewrite. You can select it, then click Install.

iis-url-rewrite-2

Once installed, click on your site, then double click URL Rewrite.


iis-url-rewrite-3

Now click Add Rules
iis-url-rewrite-4

Conveniently, this “default” redirect is already there for you to select.
iis-url-rewrite-5

Step back: this dropdown list you will see is related to your site bindings. You might need to go back and make sure you have all your bindings in place. Note that I don’t have HTTPS in here. You could select that, as well if you wanted everything to redirect to https://www.domain.com
iis-url-rewrite-6

Here’s the prompt for selecting the canonical domain name, listed from the site bindings
iis-url-rewrite-7

Now that the rule is added, you want to confirm the rules, so click Edit. You can also rename it by clicking Rename.

iis-url-rewrite-8

Review and scroll down to the bottom. Confirm the Action type is Redirect and the redirect type. For SEO you want this to be a 301, meaning the “real” site lives only at www.domain.com. Make sure to hit apply if you update anything, then click Back to Rules.

Note: see the “Append Query String”? If you have http://domain.com/xyz=1  it will redirect to http://www.domain.com/xyz=1. This should be checked by default and is recommended.

iis-url-rewrite-9

That’s it, you’re done!

Additional information:

Here’s the web config:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
 <system.webServer>
 <rewrite>
 <rules>
 <rule name="CanonicalHostNameRule1">
 <match url="(.*)" />
 <conditions>
 <add input="{HTTP_HOST}" pattern="^www\.processio\.com$" negate="true" />
 </conditions>
 <action type="Redirect" url="http://www.processio.com/{R:1}" />
 </rule>
 </rules>
 </rewrite>
 </system.webServer>
</configuration>

 

 

Add a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.