Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
阻止robots.txt中包含数字的URL_Url_Robots.txt - Fatal编程技术网

阻止robots.txt中包含数字的URL

阻止robots.txt中包含数字的URL,url,robots.txt,Url,Robots.txt,我的网站允许搜索引擎以两种格式索引同一页面,如: ‪www.example.com/page-1271.html‬ www.example.com/page-1271-page-title.html 我所有的网站页面都是这样的。那么,如何阻止robots.txt文件中的第一种格式呢?我的意思是,有没有这样的代码: Disallow: /page-(numbers).html robots.txt中没有这样的regexp选项。您有两个选择: 1) 将机器人禁止信息放入html文件中的head

我的网站允许搜索引擎以两种格式索引同一页面,如:

  • ‪<代码>www.example.com/page-1271.html‬
  • www.example.com/page-1271-page-title.html
我所有的网站页面都是这样的。那么,如何阻止robots.txt文件中的第一种格式呢?我的意思是,有没有这样的代码:

Disallow: /page-(numbers).html

robots.txt中没有这样的regexp选项。您有两个选择:

1) 将机器人禁止信息放入html文件中的head元素中。 2) 编写一个脚本,将每个可阻止的html文件作为单独的一行添加到robots.txt中 3) 将内容页放在单独的目录中,并禁止访问该目录

一些搜索引擎(如谷歌),但并非所有搜索引擎都尊重模式匹配:


在这里,允许覆盖禁止,这也不是所有搜索引擎都支持的。最简单的方法是重新构造文件(或重写URL),或者将robots信息放入html文件中。

原始robots.txt规范没有定义任何通配符。(然而,一些解析器,比如谷歌,无论如何都增加了通配符支持。)

如果您担心搜索引擎只索引两个变体中的一个,那么robots.txt还有其他替代方案:

您可以从
example.com/page-1271.html重定向(使用301)‬
example.com/page-1271-page-title.html
。这个解决方案将是最好的,因为现在每个人(用户、机器人)都将使用相同的URL

或者你也可以用这个。在
example.com/page-1271.html上‬
(或在两种变体上)您可以将
链接
元素添加到
标题

<link href="example.com/page-1271-page-title.html" rel="canonical" />


这告诉搜索引擎机器人等使用
canonical
URL而不是当前URL。

谢谢,实际上它们不是html文件,它们是php,每个页面都可以以上述格式读取,因此我不能将不允许的信息放在标题中,因为这将不允许两个URL,这就是为什么我不能在单独的目录中移动不需要的URL。感谢您的帮助请注意,它是
robots.txt
,而不是
robot.txt
。我在你的问题中更正了它。
<link href="example.com/page-1271-page-title.html" rel="canonical" />