vml19
vml19

Reputation: 3864

IIS 7 URL Redirecting

If a user type http://mysite.com in browser, the user should be redirected to https://mysite.com

Could it be done by the following.

<rewrite>
<rules>
    <rule name="Enforce canonical hostname" stopProcessing="true">
        <match url="(.*)" />
        <conditions>
            <add input="{HTTP_HOST}" negate="true" pattern="^www\.mysite\.com$" />
        </conditions>
        <action type="Redirect" url="https://www.mysite.com/{R:1}" redirectType="Permanent" />
    </rule>
</rules>

Upvotes: 0

Views: 185

Answers (2)

ImmortalStrawberry
ImmortalStrawberry

Reputation: 6101

If you don't really care about redirecting back to the same "SSL version" of the URL you entered, then this method works every time.

In IIS make sure SSL is enforced. Then add a custom Error Page for the code "403.4" "Choose Respond with a 302 Redirect" and enter the https:\ URL of your homepage.

When a user enters e.g. http://mysite.com they are redirected back to https://mysite.com

However, if they enter http://mysite.com/Stuff/Foo?All then they are also redirected back to the homepage.

In most situations I've come across, this behaviour is enough.

Upvotes: 1

Ashok Padmanabhan
Ashok Padmanabhan

Reputation: 2120

This should have all the info you need and here

Upvotes: 0

Related Questions