HTTP redirection to HTTPS

Redirecting and Rewriting a url is one of the most important factor that leads to SEO (Search Engine Optimization). Not just for the computer brains, but also particularly for human brains as it is easier to remember a well formatted url.

It is really difficult for a normal guys out there to remember the whole url, especially if its an HTTPS. Most of the internet users don’t even know what http is.

Lets create a scenario first, in order to know why this is necessary for us. Suppose you got a banking website, which requires the website to use SSL, and require https. Would you put a link in your homepage saying that click here to go to the main banking page and finally lead the customer to your https website? Wouldn’t that be closer to saying goodbye for the customer. Why don’t we automate it?

Now, I’m going to discuss on how to automate the redirection of HTTP to HTTPS. For this tutorial you will require IIS7 and the Rewrite Module to be installed. (Sorry IIS6 guys)

Lets say you want to redirect http://www.mybank.com to https://www.mybank.com

You will require to edit web.config which is on your http site, and add the following line.

<system.webServer>
    <rewrite>
        <rules>

            <rule name="Redirect to HTTPS" stopProcessing="true">
                <match url="(.*)" />
                <conditions>
                    <add input="{HTTPS}" pattern="^OFF$" />
                </conditions>
                <action type="Redirect" url="https://www.mybank.com" redirectType="SeeOther" />
            </rule>

        </rules>
    </rewrite>
</system.webServer>

That's it, and you are done.

If you want to check out a real example and think why it is important to your website check out http://www.paypal.com.

Web.config file can be downloaded from here:
       iis7_rewrite_http_to_https.zip (397.00 bytes)


blog comments powered by Disqus