asp.net - 将规则重写为 HTTPS 和 WWW,除非在本地主机上
问题描述
由于我的粗心,删除了以前的帖子并发布了实时域。
我在构建一个正常运行的 Web.config 规则时遇到了麻烦,该规则将引导来自http:// to https://www
and的流量http://www to https://www
,除了在我进行某些开发https:// to https://www
时localhost
或在进行某些开发时。127.0.0.1
网页配置
<rewrite>
<rules>
<clear />
<rule name="Redirect non-www OR non-https to https://www">
<match url=".*" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="^example.com$" />
<add input="{HTTPS}" pattern="off" />
</conditions>
<action type="Redirect" url="https://www.example.com/{R:0}" redirectType="Permanent"/>
</rule>
</rules>
更新和工作规则,也许有人可以指出一些错误?
<rewrite>
<rules>
<clear />
<rule name="Enforce HTTPS" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTPS}" pattern="off" />
<add input="{HTTP_HOST}" matchType="Pattern"
pattern="^localhost(:\d+)?$" negate="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}"
appendQueryString="true" redirectType="Permanent" />
</rule>
<rule name="Redirect example.com to www.example.com"
enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern="^[^www]" />
<add input="{HTTP_HOST}" matchType="Pattern"
pattern="^localhost(:\d+)?$" negate="true" />
</conditions>
<action type="Redirect" url="https://www.example.com/{R:1}"
appendQueryString="true" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
解决方案
推荐阅读
- java - org.openqa.selenium.ElementClickInterceptedException:元素点击被拦截:元素...在点(376、846)不可点击
- python - Selenium 将链接作为列表读取?
- c# - 处理实体框架的时间过长
- spring-boot - 使用 Reactive webclient 递归调用 Mono 函数
- python - qt.qpa.plugin:即使找到了,也无法在“”中加载 Qt 平台插件“xcb”。
- mysql - 如何将MYSQL中的混合日期转换为yyyy-mm-dd格式
- r - 在闪亮的应用程序中使用两个操作按钮更新反应对象
- java - 为什么浏览器请求没有数据?java的ServerSocket和socket
- ag-grid - AG Grid 剪辑单元格中的长文本并在单击时全部显示
- javascript - 舍入一个数字,使其在 javascript 中不为 0