我需要两者兼而有之https
and non-www
重写,同时也不对域进行硬编码,因为我们有很多服务器。这需要在web.config
,不在IIS
.
我读过很多文章:
- http://www.iis.net/learn/extensions/url-rewrite-module/url-rewrite-module-configuration-reference http://www.iis.net/learn/extensions/url-rewrite-module/url-rewrite-module-configuration-reference
- http://madskristensen.net/post/url-rewrite-and-the-www-subdomain http://madskristensen.net/post/url-rewrite-and-the-www-subdomain
- 如何设置asp.net web.config将http重写为https并将www重写为非www https://stackoverflow.com/questions/29597716/how-to-set-asp-net-web-config-rewrite-http-to-https-and-www-to-non-www
The https
重写作品,non-www
才不是。
<rule name="Redirect to HTTPS" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
</rule>
<rule name="Remove WWW" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<conditions>
<!--<add input="{CACHE_URL}" pattern="*://www.*" />-->
<!--<add input="{HTTP_HOST}" pattern="*://www.*" />-->
<add input="{HTTP_HOST}" pattern="^.*www.*" />
</conditions>
<action type="Redirect" url="https://{SERVER_NAME}/{R:1}" redirectType="Permanent" />
// i've also tried
// url="{C:2}/{R:1}"
// url="{C:1}/{C:2}"
</rule>
我测试了正则表达式^.*www.*
在正则表达式测试器上,它匹配www.testing.com
但不是testing.com
- 所以我假设该模式会捕获它。
我需要重定向的 URL:
- 测试.com --->https://testing.com https://testing.com
- www.testing.com --->https://testing.com https://testing.com
- www.testing.com/xyz/ --->https://testing.com/xyz/ https://testing.com/xyz/
是我自己的问题 - 没有 DNSwww
,因此重定向不会自行解析。
使用的代码:
<rule name="Redirect to HTTPS" stopProcessing="true">
<match url="(.*)"/>
<conditions>
<add input="{HTTPS}" pattern="^OFF$"/>
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent"/>
</rule>
<rule name="Remove WWW" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<conditions>
<add input="{CACHE_URL}" pattern="*://www.*" />
</conditions>
<action type="Redirect" url="{C:1}://{C:2}" redirectType="Permanent" />
</rule>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)