tug*_*erk 8 regex asp.net iis https iis-7
我在我的整个网站上强制使用我的web.config文件中的以下代码进行SSL;
<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>
但我想做的是强制ssl只有~/purchase/和~/account/路径和它们下面.该匹配网址应该是什么?
注意正则表达式也适用于我和通配符.
你应该使用这个模式(这会为工作/purchase/something以及/account/something-else):
^((purchase|account)/.*)$
你必须记住,该URL应该没有前导斜杠/.
<?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>
| 归档时间: | 
 | 
| 查看次数: | 3766 次 | 
| 最近记录: |