重定向 URL 中的第二个尾部斜杠

Tri*_*ido 1 iis url-rewriting iis-10

我正在使用 URL 重写来强制 http 到 https 重定向。它正在工作,只是它在 URL 中添加了第二个尾部斜杠。例如,如果我访问http://example.com,重写的 URL 最终会是https://example.com//。我什至不想要 1 个尾部斜杠,更不用说 2 个,而且我无法摆脱它。我尝试了这个解决方案,但没有成功。可能是因为这个人想去掉结尾的斜杠,而我有两个斜杠,所以它不匹配?

我的 web.config 文件中有以下规则。我正在运行带有 IIS 10 和 URL 重写模块的 Windows Server 2019。如果有人能告诉我哪里出错了,我将不胜感激!

<rule name="HTTPS Redirect" stopProcessing="true">
    <match url="(.*)" />
        <conditions>
            <add input="{HTTPS}" pattern="^OFF$" />
        </conditions>
    <action type="Redirect" url="https://{HTTP_HOST}/{REQUEST_URI}" appendQueryString="false" />
</rule>
<rule name="SEO - Remove trailing slash" stopProcessing="false">
    <match url="(.+)/$" />
        <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
            <add input="{HTTP_METHOD}" pattern="GET" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
        </conditions>
    <action type="Rewrite" url="_{R:1}" />
</rule>
Run Code Online (Sandbox Code Playgroud)

Sig*_*gja 5

只需删除操作重定向 URL 中 {HTTP_HOST} 和 {REQUEST_URI} 之间的斜杠即可。

https://serverfault.com/questions/893315/best-way-to-redirect-all-http-to-https-in-iis