views:

76

answers:

4

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 possible to do this in the web.config file? If not, how else can I achieve this?

Cheers, Curt.

+3  A: 

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.

Franci Penov
This doesn't seem to work for me. Could it have anything to do with the website being set up on an IIS6 server?
Curt
Unfortunately, URL Rewrite does not work on IIS6.
Franci Penov
+1  A: 

Unfortunately URL Rewrite module is not available on IIS6.

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

rochal
+1  A: 

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.

burnt_hand
A: 

This has worked perfectly for me:

http://stackoverflow.com/questions/1872227/iis-6-how-to-redirect-from-http-example-com-to-http-www-example-com/1872647#1872647

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

Curt