开发者

Redirect *.domain.com & domain.com to www.domain.com

I've got an Search Engine Optimisation problem where users are able to access my site by specifying any sub-domain. This is causing duplicate page issues with SEO.

For example if a user mis-types 'www' then posts a link on a forum, google is crawling 'wwww.domain.com'. Furthermore, google is also crawling 'domain.com'.

I need a way of forcing the site to always redirect to 'www.domain.com' regardless of how the user accesses the site.

Is it p开发者_运维百科ossible to do this in the web.config file? If not, how else can I achieve this?

Cheers, Curt.


You can do this using the IIS URL Rewrite module. Here's the config to rewrite domain.com to www.domain.com:

<system.webServer>
    <rewrite>
        <rules>
            <rule name="Canonical host name">
                <match url="^(.*)" />
                <conditions>
                    <add input="{HTTP_HOST}" pattern="^www\.domain\.com$" negate="true" />
                </conditions>
                <action type="Redirect" url="http://www.domain.com/{R:1}" />
            </rule>
        </rules>
    </rewrite>
</system.webServer>

You might need to modify the regex a bit or add a second rule to support rewrite of specific subdomains as well.


Unfortunately URL Rewrite module is not available on IIS6.

If you want to use url rewriting, you could check one of the following:

  • http://www.isapirewrite.com/ (not free)

  • http://urlrewriter.net/ (free)

  • http://cheeso.members.winisp.net/IIRF.aspx (my favourite)


Ah, just did this!

Set the default site to just redirect all calls using URL Redirect to your www.site.com, then create another site with your actual content that binds just to the www subdomain.

This will mean that all traffic will be redirected to the www site if there is no other binding available.


This has worked perfectly for me:

IIS 6 how to redirect from http://example.com/* to http://www.example.com/*

I had to change a bit of the code to get it to work with my Url-Rewriting, but apart from that, spot on!

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜