【发布时间】:2021-05-20 09:16:33
【问题描述】:
每当我在我的 Web 服务器上定位包含索引文件的子文件夹时,我都会对 IIS 10 放置一个尾部斜杠失去理智。它不仅总是通过 301 重定向到尾部斜线,而且我的 SEO 排名受到严重伤害,以至于我无法在任何地方排名。我到处都阅读了所有著名的答案(包括描述的著名规则here),但没有任何帮助。
例子:
我有这个结构
根
- 套(子文件夹)
- index.php
- test.php
这太糟糕了,甚至我的主页(我的/root)也被从 website.com 重定向到 301 到 website.com/
当我访问 website.com/sets 时,我故意不链接到 website.com/sets/index.php,我得到了斜杠。当我去 website.com/test.php (或什至 website.com/test 重写.php)时,我很好。没有尾随斜杠。
这是我在 web.config 中的全部规则。我试过禁用“删除 PHP”规则,我仍然得到斜杠。我已经将它们移动了 - 没有,我尝试将一些 htaccess 示例转换为 web.config - 没有。此刻我很绝望。
<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" enabled="true" 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" enabled="true" 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>
<!--To always remove trailing slash from the URL - Does not work!!!!-->
<rule name="Remove trailing slash" stopProcessing="true">
<match url="(.*)/$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="{R:1}" />
</rule>
<rule name="Prevent image hotlinking" enabled="false"> <!-- turned off for now -->
<match url=".*\.(gif|jpg|png)$" />
<conditions>
<add input="{HTTP_REFERER}" pattern="^$" negate="true" />
<add input="{HTTP_REFERER}" pattern="^https://www.website\.com/.*$" negate="true" />
</conditions>
<action type="Rewrite" url="/images/say_no_to_hotlinking.jpg" />
</rule>
</rules>
编辑:
我读过这个 - https://developers.google.com/search/blog/2010/04/to-slash-or-not-to-slash。如果我理解正确 - 如果一个 301 到另一个,另一个返回 200 - 没关系....嗯 .. 所以我不需要改变任何东西?就这样好吗?
【问题讨论】:
标签: php web-config iis-10 trailing-slash