Redirecting to Canonical URL in IIS7
If you are using IIS7, it’s very easy to ensure that all requests always go to your preferred canonical URL. It’s a two step process:
Step 1: Install the UrlRewrite module for IIS: http://www.iis.net/expand/URLRewrite
Step 2: Add the following rule to your applications web.config file:
01.
<configuration>
02.
<system.webServer>
03.
<rewrite>
04.
<rules>
05.
<clear />
06.
<rule name="Redirect from www" stopProcessing="true">
07.
<match url=".*" />
08.
<conditions>
09.
<add input="{HTTP_HOST}" pattern="^www.yoursite.com$" />
10.
</conditions>
11.
<action type="Redirect" url="http://yoursite.com/{R:0}" redirectType="Permanent" />
12.
</rule>
13.
</rules>
14.
</rewrite>
15.
</system.webServer>
16.
</configuration>
IMPORTANT: When using the above code, take care to merge it with your existing web.config without duplicating any existing elements.
I like my URL’s to be in the format http://mysite.com. If you prefer http://www.mysite.com, simply remove “www.” from the <add> element and add it to the <action> element’s “url” attribute.
debendranandi
Nice one...admin can more secure after implement it.
Thanks for good posting
Christian
Is this working for DotNetNuke?
edu
thanks mate!