我在IIS中使用3个与域无关的重写规则。首先,我从HTTP重定向到HTTPS,然后从裸域重定向到www,最后我通过重写从URL中删除.php。
但是,我看到每当我访问作为子文件夹的页面并访问其中的索引页面时,URL末尾都会添加一个斜杠。示例:
根->子文件夹,其中包含index.php的项
URL-www.xxx.net/items /
如果我访问该文件夹中除index.php以外的文件,则没有斜杠
根->子文件夹,其中包含2.php的项
URL-www.xxx.net/items/2
通常,我不在乎,但我注意到Google和爬虫将www.xxx.net/items和www.xxx.net/items/视为会导致问题的不同实体。
我知道这很容易,但是现在无法查明。有人可以告诉我如何摆脱这种行为吗?
以下是规则:
<rewrite>
<rules>
<rule name="HTTP/S to HTTPS Redirect" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{SERVER_PORT_SECURE}" pattern="^0$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" />
</rule>
<rule name="Redirect naked domain to www" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" negate="true" pattern="^www\." />
</conditions>
<action type="Redirect" url="https://www.{HTTP_HOST}{REQUEST_URI}" appendQueryString="false" redirectType="Permanent" />
</rule>
<rule name="Remove PHP" stopProcessing="true">
<match url="^(.*)$" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}.php" matchType="IsFile" ignoreCase="false" />
</conditions>
<action type="Rewrite" url="{R:1}.php" />
</rule>
</rules>
</rewrite>
答案 0 :(得分:0)
在阅读了大量相关内容后,事实证明这是非常预期的行为,您需要将其考虑在内。基本上,当您知道将获得尾部斜杠时,请确保您的链接也指向此页面最后包含尾部斜杠,这样您就不会得到重定向。