我有一些网站example.org
,我在上面保留了 example.com/project1
之类的子网站和 example.com/project2
等等。我需要简单的HTTP→HTTPS
仅在某些子站点上重定向,但不想手动将其写入代码文件。
于是我找到了URL-Rewrite2
他的模块和规则:
<rewrite>
<rules>
<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}" />
</rule>
</rules>
</rewrite>
它最多只能解决一个问题:它从
http://example.com/project1
重定向。至https://example.com/
,因此它丢失了子站点 URL 部分和任何参数。如何解决这个问题?
UPD:使用此规则
<rule name="Redirect to HTTPS" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{UNENCODED_URL}" />
</rule>
子站点通常重定向,但参数重复。
http://example.com/project1?page=2
变成 https://example.com/project1?page=2&page=2
.我做错了什么?
最佳答案
使用此规则完成:
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect to HTTPS" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{UNENCODED_URL}" appendQueryString="false" />
</rule>
</rules>
</rewrite>
</system.webServer>
在子网站上运行良好。
关于IIS URL 重写 : HTTP to HTTPS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34284181/