即使 URL 重写如下,我也无法删除网站 URL 的尾部斜杠:http://ruslany.net/2009/04/10-url-rewriting-tips-and-tricks/ http://ruslany.net/2009/04/10-url-rewriting-tips-and-tricks/.
真的很令人沮丧,因为它应该如此简单,但我的尝试没有产生任何结果。
我什至创建了一个测试目录并添加了名为desktops.aspx 的文件和名为desktops 的子文件夹。
没有子目录“/test/desktops”加载正常,因为我将默认文档设置为查看desktops.aspx。
创建子文件夹并仍然引用“/test/desktops”时,它会强制使用斜杠并查看子目录。
为什么 IIS 会这样做,因为它应该先查找文件,然后再查找子目录正确?服务器端是否有任何设置可以强制恢复斜杠?
URL 重写片段:
<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>
欢迎任何帮助
您正在使用类型的操作Rewrite
但你想要一个Redirect
.
将您的配置更改为:
<rule name="SEO - Remove trailing slash" stopProcessing="false">
<match url="(.*)/$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Redirect" url="{R:1}" />
</rule>
你还需要改变url="(.+)/$"
to url="(.*)/$"
.
TIP:
测试模式的最佳方法是使用 IIS 测试模式工具。
在网站的根目录 -> URL 重写 -> 创建空白规则 -> 单击测试模式:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)