asp.net – web.config使用规则将非www或非https重定向到https:
发布时间:2020-12-16 06:38:57 所属栏目:asp.Net 来源:网络整理
导读:我需要使用web.config中的规则将所有非www或非https流量重定向到https:// www http://domain.com -- https://www.domain.comhttp://www.domain.com -- https://www.domain.comhttps://domain.com -- https://www.domain.com 我修改了Web.config. Redirect a
我需要使用web.config中的规则将所有非www或非https流量重定向到https:// www
http://domain.com --> https://www.domain.com http://www.domain.com --> https://www.domain.com https://domain.com --> https://www.domain.com 我修改了Web.config. Redirect all traffic to www.my… Using rules element.的规则,但无法将http://www.domain.com重定向到https://www.domain.com. <rewrite> <rules> <clear /> <rule name="Redirect to www subdomain"> <match url=".*" /> <conditions logicalGrouping="MatchAll"> <add input="{HTTP_HOST}" pattern="^(www.)(.*)$" negate="true" /> <add input="{SERVER_PROTOCOL}" pattern="^(.*)(/.*)?$"/> </conditions> <action type="Redirect" url="https://www.{HTTP_HOST}/{R:0}" redirectType="Permanent"/> </rule> </rules> </rewrite> 解决方法
这会将所有非www或非https重定向到
https://www
<rewrite> <rules> <rule name="non-www-https to www https" enabled="true" stopProcessing="true"> <match url=".*" /> <conditions> <add input="{HTTP_HOST}" pattern="^[^.]+.[^.]+$" /> <add input="{HTTPS}" pattern="on" /> <add input="{HTTP_HOST}" pattern="localhost" negate="true" /> </conditions> <action type="Redirect" url="https://www.{HTTP_HOST}/{R:0}" /> </rule> </rules> </rewrite> 我在IIS express(本地主机)上添加了这一行来忽略它: <add input="{HTTP_HOST}" pattern="localhost" negate="true" /> 这样做的另一个好处是您无需在此规则中输入您的域. 你可以在这里阅读更多: (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-web-api – AttributeRouting不能与HttpConfigurat
- asp.net – 存储可变数据
- asp.net – 我想列出我的下拉列表中的所有国家/地区,我在哪
- ASP基于B/S模式的失物招领系统
- Jquery+ajax请求data显示在GridView上(asp.net)
- asp.net – Ext.net:如何设置宽度百分比而不是像素?
- Asp.Net和Asp.Net MVC中的Ajax之间的区别
- asp.net-mvc – 基于MVC中应用程序的语言选择对必需字段验证
- asp.net-mvc-3 – ASP.NET MVC 3/4是否有任何响应模板
- asp.net-mvc – 自定义WIF请求验证器无限循环