为什么 robots.txt 文件应该阻止子文件夹,但也阻止一些随机文件

问题描述 投票:0回答:1

通过将文件添加为文件夹,我为我的网站索引了一些奇怪的 URL。这里有一个示例 URL

https://www.plus2net.com/python/tkinter-scale.php/math.php

我有一个文件

tkinter-scale.php
但没有该名称的目录

同样,此 URL 也被索引,您可以将 ses 文件名作为文件夹名称包含在内。

https://www.plus2net.com/python/tkinter-sqlite.php/javascript_tutorial/asp-tutorial/site_map.php

然后我将这两行添加到

robots.txt
文件中,删除
/python/
之后的所有子文件夹,这样我就可以索引 python 文件夹内的文件,但不能索引到下一级。

Allow: /python/$
Disallow: /python/

现在我有一大堆被

robots.txt
文件阻止的文件列表,这是正确的,它们位于 python 目录的子文件夹内。但有 5 个文件也被阻止(在近 500 个列表中)。

https://www.plus2net.com/python/string-rjust.php
https://www.plus2net.com/python/dj-mysql-add-data.php
https://www.plus2net.com/python/next.php
https://www.plus2net.com/python/test.csv
https://www.plus2net.com/python/string-islower.php

为什么这些文件被阻止? (这些文件没有页面级阻塞)

blocking robots.txt
1个回答
0
投票

您当前的

robots.txt
Allow
规则不允许
python
目录中的任何内容。既不是文件,也不是子目录,只是基目录本身。在我看来,您希望您的
robots.txt
看起来像:

User-Agent: *
Disallow: *.php/

User-Agent: *
Disallow: /python/
Allow: /python/$
Allow: /python/*.php$

这两个对于主要搜索引擎来说是相当相同的。它们处理

Allow
指令,
*
作为通配符,
$
作为“结尾”。对于大多数不了解 Google
robots.txt
语法扩展的其他抓取工具,这些规则会有所不同。第一组规则将允许他们抓取所有内容,第二组规则将阻止整个
python
目录。

为了将来参考,我建议针对

Google 的 
robots.txt 测试工具
测试您的 
robots.txt


解决此问题的另一种方法是将 Web 服务器配置为不允许在文件名后添加路径。如果您使用 Apache,您可以在

httpd.conf
.htaccess
中设置以下内容。

AcceptPathInfo Off

© www.soinside.com 2019 - 2024. All rights reserved.