简体   繁体   中英

Force Https on an ASP.NET app running on IIS 7.5

I am forcing SSL on my entire site with the following code on my web.config file;

<system.webServer>
    <rewrite>
        <rules>
            <rule name="Redirect HTTP to HTTPS" stopProcessing="true">
                <match url="(.*)"/>
                <conditions>
                    <add input="{HTTPS}" pattern="^OFF$"/>
                </conditions>
                <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="SeeOther"/>
            </rule>
        </rules>
    </rewrite>
</system.webServer>

but what I would like to do is to force ssl only the ~/purchase/ and ~/account/ path and under them. what should be the match url for that?

NOTE Regular Expressions also would work for me here as well as wildcard.

You should use this pattern (this will work for /purchase/something as well as /account/something-else ):

^((purchase|account)/.*)$

You have to remember, that URL should have no leading slash / .

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Force HTTPS" stopProcessing="true">
                    <match url="^((purchase|account)/.*)$" />
                    <conditions>
                        <add input="{HTTPS}" pattern="^OFF$" />
                    </conditions>
                    <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

you would do something like this (2 separate rules for simplicity)

  <match url="/purchase/(.*)"/>

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