Redirect 仅重写子文件夹(HTTP到HTTPS)重定向到站点根目录
我正在尝试将IIS 8.5 web服务器上特定子文件夹的HTTP重写为HTTPS,但它不起作用。我读过无数其他解决方案和博客帖子,但我尝试过的都不管用Redirect 仅重写子文件夹(HTTP到HTTPS)重定向到站点根目录,redirect,iis-8,url-rewrite-module,Redirect,Iis 8,Url Rewrite Module,我正在尝试将IIS 8.5 web服务器上特定子文件夹的HTTP重写为HTTPS,但它不起作用。我读过无数其他解决方案和博客帖子,但我尝试过的都不管用 应该重定向到。。。(相同的url,但使用https) 但实际上是重定向到。。。(使用https的站点根目录) 加载。。。(所需的带有https的url) 也重定向到。。。(使用https的站点根目录) 它正在从url中删除子文件夹 此文件夹还需要使用Windows身份验证进行保护,我可以使用Windows身份验证,但是https重定向在
应该重定向到。。。(相同的url,但使用https)
但实际上是重定向到。。。(使用https的站点根目录)
加载。。。(所需的带有https的url)
也重定向到。。。(使用https的站点根目录)
它正在从url中删除子文件夹 此文件夹还需要使用Windows身份验证进行保护,我可以使用Windows身份验证,但是https重定向在启用或不启用身份验证的情况下都会失败,因此我认为这不是原因 在IIS中,我选择了所需的子文件夹(/three/,在上面的示例中),并在那里创建了重写规则
<rewrite>
<rules>
<clear />
<rule name="HTTP to HTTPS redirect" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" redirectType="SeeOther" />
</rule>
</rules>
</rewrite>
这当然适用于所需子文件夹中包含的任何文件和文件夹。(/三)
我尝试了这个,它重定向到了明显正确的url,但出现了“重定向太多”错误:
您应该避免这样做: 在IIS中,我选择了所需的子文件夹(/three/) 并在那里创建了重写规则
<rewrite>
<rules>
<clear />
<rule name="HTTP to HTTPS redirect" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" redirectType="SeeOther" />
</rule>
</rules>
</rewrite>
而是在应用程序根目录下的Web.config
中设置重写规则。通过将特定文件夹包含在match
参数中,可以将其重定向到HTTPS,如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect Subfolder" stopProcessing="true">
<match url="^one/two/three/" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" appendQueryString="false" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
请注意,这是一个最小的Web.config
文件,可以满足您的需要。如果应用程序的根文件夹中已经包含Web.config
,则必须将上述内容合并到解决方案中