我正在尝试在web.config中添加重定向规则,以便仅在HTTPS中提供我的网页,而根本不提供HTTP;到目前为止,我已经使用了这个规则集(连同我的404重定向):
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<clear />
<rule name="Redirect to https" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
</rule>
</rules>
</rewrite>
<directoryBrowse enabled="false" />
<httpErrors errorMode="Custom" existingResponse="Auto">
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" subStatusCode="-1" prefixLanguageFilePath="" path="index.php" responseMode="Redirect" />
</httpErrors>
</system.webServer>
</configuration>
然而,这会导致ERR_TOO_MANY_REDIRECTS;这个web.config有什么问题导致这个?它似乎适用于其他用户。
我已经在这些帖子中尝试过建议; Redirect loop when forcing HTTPS,URL Rewrite causing redirect loop,this blog和this blog。
答案 0 :(得分:0)
也许我来晚了一点,但是以下重写规则有助于解决重定向错误:
<rule name="Redirect to https" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^example\.com$" />
<add input="{SERVER_PORT}" pattern="^80$" />
</conditions>
<action type="Redirect" url="https://www.example.com/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>