IIS Forces甚至使用URL Rewrite删除它

fse*_*rio 7 iis-7 url-rewriting trailing-slash

即使使用以下URL重写URL,我也无法删除我网站的URL的斜杠: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>
Run Code Online (Sandbox Code Playgroud)

任何帮助都会受到欢迎

che*_*fly 7

您正在使用类型的操作,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>
Run Code Online (Sandbox Code Playgroud)

您还需要更改url="(.+)/$"url="(.*)/$".

小费:

测试模式的最佳方法是使用IIS测试模式工具.
在您网站的根目录 - > URL重写 - >创建空白规则 - >单击测试模式: