我在我的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 / path并在它们下面.该匹配网址应该是什么?
注意正则表达式在这里也适用于我和通配符.
解决方法
您应该使用此模式(这将适用于/ 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>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。