If you are implementing Google analytics, Google treats
http://www.example.com and http://example.com as different website and give different
analytics reports. But in original both sites are same.
Now your client demanding that both URL http://www.example.com and http://example.com should redirect to single URL
as http://www.example.com
How to solve this?
You must have URL
Rewrite module in IIS for this. If you have not then download and install
from http://www.iis.net/downloads/microsoft/url-rewrite
Now make entries in web.config between <system.webServer> … </system.webServer> tag by specifying old URL
lists mapping with new single URL. Finally your config file entry looks like
<rewrite>
<rules>
<rule name="CanonicalHostNameRule1">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www\.example\.com$" negate="true" />
</conditions>
<action type="Redirect" url="http://www.example.com/{R:1}" />
</rule>
</rules>
</rewrite>
You
can do all these activities from IIS as well and IIS will make entry in
web.config for you.
Please leave your comments or share this tip if it’s
useful for you.