【问题标题】:URL Rewrite update protocol and domain if URL is http://如果 URL 为 http://,则 URL 重写更新协议和域
【发布时间】:2014-08-20 13:54:25
【问题描述】:
我想使用在 IIS 8.5 上运行的 URL 重写将所有对 http://www.domain.com/csp/ 的调用重定向到 https://secure.doman.com/csp/。我希望浏览器上的 URL 相应更新。我无法让它工作。
下面是带有规则的 web.config 文件部分
<rules>
<rule name="CSP to SSL" enabled="true" stopProcessing="true">
<match url="^http://www.domain.com/csp/(.*)$" />
<conditions>
<add input="{CACHE_URL}" pattern="^http://" />
</conditions>
<action type="Redirect" url="https://secure.domain.com/csp/{R:1}" />
</rule>
</rules>
谢谢。
【问题讨论】:
标签:
url
iis
url-rewriting
rewrite
【解决方案1】:
感谢 peterviola 在http://forums.iis.net/t/1214515.aspx?Change+to+https+and+adjust+domain+if+URL+uses+http+and+matches+a+particular+path 的回复,我设法找到了我正在寻找的解决方案。
<rule name="csp2HTTPS" enabled="true" stopProcessing="true">
<match url="(.*)csp/(.*$)" ignoreCase="true" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTPS}" pattern="off" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" appendQueryString="true" redirectType="Permanent" />
</rule>
<rule name="csp2subdomain" enabled="true" stopProcessing="true">
<match url="(.*)csp/(.*$)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^(www.|)domain.com$" />
</conditions>
<action type="Redirect" url="https://secure.domain.com{REQUEST_URI}" appendQueryString="true" redirectType="Permanent" />
</rule>
上述解决方案有效。我不明白为什么不能使用一个规则来完成。
希望这会有所帮助。