Redirect url from WWW to non-WWW in IIS 7.5

Phat Nguyen
IIS and Windows Server

--

Server infomation and dependence

  • Windows server 2008 R2
  • IIS 7.5
  • Extention URL Rewrite is already installed

Step by step

1. Add your website to IIS

Add your website to IIS

With no www before the domain

2. Add a Site bindings

Add one more domain with www.

Add a Site bindings to you website

3. Use URL Rewrite extention

Use URL Rewrite extention

In URL Rewite

  • Click Add rule(s)…
  • Choose Canonical domain name.
  • Select the primary host name: mydomain.com (without www).
  • Now you have a new Rewrite rules. Move up new rule to the top.
  • You can open this Rule to see the details rule as below.
Inbound rule for Cannonical Host Name IIS 7
  • And your web.config also changes, this is the result of all abow steps in this section (section 3). And you can add your rules manually to web.config instead of use URL Rewrite guide.

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

Pretty version is here.

That’s all you can do to rewrite WWW to non — WWW in IIS7.

--

--