开发者

Redirect visitors to the canonical URL for a page using IIS

I want to ensure that anybody who goes to http://example.com/* get开发者_运维百科s automatically redirected to http://www.example.com/*. Currently, IIS allows either URL form to work, meaning that any page can be accessed at multiple URLs, which has a number of disadvantages (SEO, etc).

Is there any way to do this built into IIS (especially IIS 6) without setting up a third-party rewriting engine like this? It seems like a bazooka to kill a mosquito.


The easy way would be to simply remove the DNS entries for 'www.mysite.com', so the only DNS entries that exist are for 'mysite.com'.

Alternatively, here's a couple of techiques for redirecting to a canonical URI:

  • http://www.kalyani.com/2010/01/redirecting-to-canonical-url-in-iis7/
  • https://web.archive.org/web/20211020203216/https://www.4guysfromrolla.com/articles/072810-1.aspx
  • http://www.stevenhargrove.com/redirect-web-pages/

Basically you want to hand back a 301 Moved Permanently status for the non-canonical URIs, along with the canonical URI so the user agent may load it instead.


I have another solution for you:

<rule name="Canonical domain name" enabled="true" stopProcessing="true">
    <match url="(.*)" />
    <conditions>
        <add input="{HTTP_HOST}" negate="true" pattern="^www\.([.a-zA-Z0-9]+)$" />
    </conditions>
    <action type="Redirect" url="http://www.{HTTP_HOST}/{R:0}" appendQueryString="true" redirectType="Permanent" />
</rule>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜