IIS 7.5 URL Redirect for specific patterns

后端 未结 1 722
难免孤独
难免孤独 2021-01-27 13:48

When user enters domain.com it should redirect to my application which is https://www.domain.com. Currently it is not happening and it is showing a page \"This Connection is Unt

相关标签:
1条回答
  • 2021-01-27 14:36

    Your rewrite rule is just redirecting to the same domain. So if a user enters just domain.com (defaulting to http) it will redirect to https://domain.com. If your SSL certificate does not contain domain.com but only www.domain.com it will cause the browser to prompt a warning about a wrong certificate. Though most certificate authorities nowadays issue certificates with both the domain with and without www (but maybe yours not).

    If you want the user to always use https://www.domain.com (always with www) you should use the following rewrite rule:

    <rule name="Force HTTPS" stopProcessing="true">
        <match url="(.*)" />
        <conditions logicalGrouping="MatchAll">
            <add input="{HTTPS}" negate="true" pattern="^ON$" />
            <add input="{HTTP_HOST}" negate="true" pattern="^www\.domain\.com$" />
        </conditions>
        <action type="Redirect" url="https://www.domain.com{REQUEST_URI}" appendQueryString="false" redirectType="Permanent" />
    </rule>
    

    It will force SSL and will force www.domain.com as a host header. If not, it will issue a permanent redirect (= beter) to the same URL.

    0 讨论(0)
提交回复
热议问题