IIS即使使用URL重写也可以强制斜杠将其删除 [英] IIS Forces Slash even with URL Rewrite to remove it
问题描述
即使从以下位置重写URL,我也无法删除我站点的URL末尾斜杠:
I am unable to remove the trailing slash my site's URLs even with the URL rewrite from: http://ruslany.net/2009/04/10-url-rewriting-tips-and-tricks/.
真的很令人沮丧,因为它应该是如此简单,但是我的尝试并没有产生任何结果.
Frustrating really since it should be so simple but my attempts have not produced any results.
我什至可以创建一个测试目录,并添加名为Desktops.aspx的文件和名为Desktops的子文件夹.
I even went as far as to create a test directory and added file called desktops.aspx and and sub folder called desktops.
没有子目录"/test/desktops"的加载很好,因为我将默认文档设置为查看desktops.aspx.
without the sub directory "/test/desktops" loads fine since i set the default document to look at desktops.aspx.
创建了一个子文件夹,并且仍然引用"/test/desktops",它会强制使用斜杠并查看子目录.
with a subfolder created and still referencing "/test/desktops" it forces the slash and looks at the sub directory.
为什么IIS这样做是因为IIS应该先查找文件,然后再查找子目录?服务器端是否有任何设置可以迫使斜杠退回?
Why does IIS does this since its supposed to look for the file first then the sub directory correct? Are there any settings on the server side that would force back the slash?
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
.
You are using an action of type Rewrite
but you want a 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 =(.+)/$"
更改为 url =(.*)/$"
.
You also need to change url="(.+)/$"
to url="(.*)/$"
.
提示:
测试模式的最佳方法是使用IIS测试模式工具.
在您网站的根目录-> URL重写->创建空白规则->单击测试模式:
The best way to test your pattern is to use the IIS test pattern tool.
At the root of your website -> URL Rewrite -> Create a blank rule -> click on test pattern:
这篇关于IIS即使使用URL重写也可以强制斜杠将其删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!