简体   繁体   中英

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>

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 eg 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.

这应该具有您需要的所有信息,并且在这里

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM