如何解决重定向 URL 中的第二个尾部斜杠
我正在使用 URL 重写来强制将 http 重定向到 https。它正在工作,只是它向 URL 添加了第二个尾部斜杠。例如,如果我转到 http://example.com,重写后的 URL 最终是 https://example.com//。我什至不想要 1 个尾部斜杠,更不用说 2 个了,我无法摆脱它。我尝试了 this 解决方案,但没有奏效。可能是因为这个人想去掉尾部的斜杠,而我有 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>
解决方法
你可以尝试使用这个 URL Rewrite 规则:
<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>
,
只需删除操作重定向 URL 中 {HTTP_HOST} 和 {REQUEST_URI} 之间的斜线。 (https://serverfault.com/questions/893315/best-way-to-redirect-all-http-to-https-in-iis)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。