Ana*_*and 39 iis web-config url-rewriting
我需要将非www网址重定向到www网址,用于http和https网址.我尝试在web.config中遵循规则.
<rule name="Redirect to WWW" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^domain.com$" />
</conditions>
<action type="Redirect" url="http://www.domain.com/{R:0}" redirectType="Permanent" />
Run Code Online (Sandbox Code Playgroud)
<rule name="Redirect to WWW https" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTPS}" pattern="^domain.com$" />
</conditions>
<action type="Redirect" url="https://www.domain.com/{R:0}" redirectType="Permanent" />
Run Code Online (Sandbox Code Playgroud)
它适用于非ssl网址,但在ssl的情况下,它从https://domain.com重定向 到http://www.domain.com
请帮我纠正我的规则.
Sat*_*pal 52
对于适用于两者Match Any
和Match All
情境的更安全的规则,您可以使用"重写映射"解决方案.这是一个非常好的解决方案,唯一的缺点是设置它需要额外的努力,因为您需要在创建规则之前创建重写映射.换句话说,如果您选择使用此作为处理协议的唯一方法,那么您将是安全的.
您可以创建名为MapProtocol的重写映射,您可以{MapProtocol:{HTTPS}}
在任何规则操作中使用该协议.
<rewrite>
<rules>
<rule name="Redirect to www" stopProcessing="true">
<match url="(.*)" />
<conditions trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^domain.com$" />
</conditions>
<action type="Redirect"
url="{MapProtocol:{HTTPS}}://www.domain.com/{R:1}" />
</rule>
</rules>
<rewriteMaps>
<rewriteMap name="MapProtocol">
<add key="on" value="https" />
<add key="off" value="http" />
</rewriteMap>
</rewriteMaps>
</rewrite>
Run Code Online (Sandbox Code Playgroud)
Cht*_*lek 13
这里的其他答案是不必要的长,这是我使用的规则(只是复制和粘贴):
<rule name="ensurewww" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{CACHE_URL}" pattern="^(.+)://(?!www)(.*)" />
</conditions>
<action type="Redirect" url="{C:1}://www.{C:2}" redirectType="Permanent" />
</rule>
Run Code Online (Sandbox Code Playgroud)
这将重定向到www版本,同时保留HTTP和HTTPS协议
希望这可以帮助.
自2018年以来,考虑每次使用https(SSL)!
所以我一起使用重定向到www和https.
<rule name="Redirect to www" stopProcessing="true">
<match url="(.*)" />
<conditions trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^domain.com$" />
</conditions>
<action type="Redirect" url="https://www.comain.com/{R:1}" redirectType="Permanent" />
</rule>
<rule name="HTTP/S to HTTPS Redirect" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{SERVER_PORT_SECURE}" pattern="^0$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" />
</rule>
Run Code Online (Sandbox Code Playgroud)
更多信息:https: //forums.realmacsoftware.com/t/effective-july-2018-google-s-chrome-browser-will-mark-non-https-sites-as-not-secure/18597
归档时间: |
|
查看次数: |
60020 次 |
最近记录: |