Configuring HTTPS and avoiding duplication of URLs using the IIS7 URL rewrite module

I need to force every request to https://www.mysite.com (always with https and www)

The site is hosted by GoDaddy, and I need to do this through the IIS7 URL rewriter module.

I was able to redirect HTTPS with the following code:

<system.webServer>
        <rewrite>
            <rules>
                <rule name="Canonical Host Name" stopProcessing="true">
                    <match url="(.*)" />

                    <conditions>
                        <add input="{HTTP_HOST}" pattern="^mysite\.com$" />
                    </conditions>

                    <action type="Redirect" url="https://www.mysite.com/{R:1}" redirectType="Permanent" />
                </rule>
            </rules>
        </rewrite>
</system.webServer>

Testing

I assume the condition is not met when I log in to www.mysite.com in the browser, so there is no redirect, and the page is used as HTTP instead of HTTPS.

, , , .

!

+3
1

emzero, , , mysite.com:

<conditions>
    <add input="{HTTP_HOST}" pattern="^mysite\.com$" />
</conditions>

: ^mysite\.com$. , URL- mysite.com mysite.com, www.mysite.com .

, www.:

<conditions>
    <add input="{HTTP_HOST}" pattern="^(www\.)?mysite\.com$" />
</conditions>

!

+4

Source: https://habr.com/ru/post/1792272/


All Articles