【发布时间】:2023-02-09 17:58:00
【问题描述】:
他们更改了 url 重写模块版本(URL 重写模块 2.1),现在从 http 到 https 的重定向不起作用。
有没有人遇到过同样的问题?
应用:角度
系统:Windows Server IIS 10
这是 web.config 文件(它适用于最早版本的 URL 重写:urlrewrite2.exe)
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<security>
<requestFiltering>
<fileExtensions applyToWebDAV="false">
<add fileExtension=".pdf" allowed="true" />
</fileExtensions>
</requestFiltering>
</security>
<directoryBrowse enabled="true" />
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Credentials" value="true" />
<add name="Access-Control-Allow-Headers" value="Content-Type" />
<add name="Access-Control-Allow-Methods" value="GET,POST,PUT,DELETE,OPTIONS" />
<add name="Access-Control-Allow-Origin" value="*" />
</customHeaders>
</httpProtocol>
<rewrite>
<rules>
<rule name="redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
谢谢。
【问题讨论】:
-
我发现您的 RewriteRule 适用于 URL Rewrite 2.1。我建议执行一次 IIS 重置并查看它是否开始工作。如果问题仍然存在,请尝试检查失败请求跟踪日志以了解问题。如果有任何错误消息/屏幕截图,您可以分享。
-
@Deepak-MSFT 我重置了,还是不行
-
@Deepak-MSFT 我发现了问题,当我将端口更改为 80 时它正在工作,但在我的情况下我需要使用另一个端口 81(因为 80 已用于另一个应用程序)。我可以从 80 端口重定向到 81 端口吗?
-
那么你的意思是你需要一个 URL Rewrite rule for
http://example.com:80tohttp://example.com:81or forhttp://example.com:80tohttps://example.com:81?请澄清一下,这可能有助于我们了解您的要求。 -
@Deepak-MSFT 我想要从 http://example.com:80 重定向到 https://example.com:443 因为现在当我想打开 example.com 时我得到这个错误“Requested URL example.com:80 “。有关信息,我将端口 81 用于 http,将端口 443 用于 https。
标签: iis https url-rewriting url-rewrite-module