Canonical host name Dubi Greenfeld
A 301 redirect allows visitors and search engines to access a web page after it has been moved. If you have changed the domain name of your web site or changed the file names of pages, then you need to link to the new URLs for visitors and search engine spiders. The permanent redirect 301 is the most search engine-friendly method of redirection to the new URL or page and is the current standard for SEO purposes.

In our case, we needed all the requests for http://electionarena.com/ to be redirect to http://www.electionarena.com, and all of that is because we had a marvels bug with Facebook.
The scenario was as follow:
You access to electionarena.com, register or login, and when you want to setup the Facebook connection, the rollback URL from Facebook redirect to www.electionarena.com, this trip ends up with the user logged out of the site and the credentials are setup in some cases.
The reason for that is that the authentication in our site relies on the cookie, but for electionarena.com and www.electionarena.com there are 2 different cookies, that the reason for ending up the trip from Facebook out of the site.

The solution for that and more other reasons is the URL rewrite especially for iis7.

1.    So first of all you need to download and install the extension for iis7 from here:
    •    For X86 servers - http://go.microsoft.com/?linkid=9722533
    •    For X64 servers - http://go.microsoft.com/?linkid=9722532
2.    Next step after installing the right version is, Creating Rewrite Rules for the URL Rewrite Module.
    We will create a simple rewrite rule that rewrites URLs by using the following format:
    http://electionarena.com
    will be rewritten as:
    http://www.electionarena.com
        1.    Go to IIS Manager.
        2.    Select Default Web Site or your named website.
        3.    In the Feature View click URL Rewrite.
        4.    In the Actions pane on right-hand side, click Add rules…
        5.    In the Add Rules dialog box, select the Canonical Domain Name rule and click Ok.
        6.    Enter the domain name you want to redirect to and click ok.
        7.    That hoe the rule look like in the web.config file:
        <system.webServer>
        <…>
        <rewrite>
                    <rules>
                        <rule name="CanonicalHostNameRule1">
                            <match Url="(.*)" />
                            <conditions>
                                <add input="{HTTP_HOST}" pattern="^www\.electionarena\.com$" negate="true" />
                            </conditions>
                            <action type="Redirect" Url="http://www.electionarena.com/{R:1}" />
                        </rule>
                    </rules>
                </rewrite>
        < … >
        </system.webServer>
        8.    That all fox…
       
For more details and information see: http://learn.iis.net/page.aspx/460/using-the-url-rewrite-module/

Enjoy!
posted: 15/09/2010 12:39:51
0 Comments