禁止robots.txt中特定网址中的所有参数

时间:2015-07-06 14:31:45

标签: seo robots.txt

我想禁止特定网址中的所有参数。

如果我添加此规则:

Disallow: /*?*

它适用于所有网址

我想做什么:

Disallow: /my-specific-url/*?*

但根据Google网站站长工具,此规则不起作用。

2 个答案:

答案 0 :(得分:1)

虽然您不能使用正则表达式,但您可以使用通配符

https://developers.google.com/webmasters/control-crawl-index/docs/robots_txt#url-matching-based-on-path-values

你有没有试过像

这样的东西
Disallow: /my-specific-url/*var1=*

答案 1 :(得分:1)

您的示例看起来应该正常工作,但您确实需要包含User-agent行。以下robots.txt文件:

User-agent: *
Disallow: /my-specific-url/*?*

将阻止以下网址:

http://example.com/my-specific-url/?
http://example.com/my-specific-url/?a=b

但它不会阻止以下内容:

http://example.com/my-specific-url/
http://example.com/some-other-url/?a=b

请注意,尾随*是无害的,但没有用处。一种更干净的方式来完成同样的事情:

User-agent: *
Disallow: /my-specific-url/*?

另请注意,主要搜索引擎支持通配符,但许多其他抓取工具不支持它们。