不允许 header 页 robots.txt

Disallow header page robots.txt

我想禁止 robots.txt 中的 header.php 被编入索引。 文件 url:

https://example.com/header.php

但我不确定什么是正确的:

Disallow: /header.php

Disallow: header.php

URL-robots.txt 中指定的路径应始终以斜杠开头(即相对根目录)。

来自Google's robots.txt specification

The [path] value, if specified, is to be seen relative from the root of the website for which the robots.txt file was fetched (using the same protocol, port number, host and domain names). The path value must start with "/" to designate the root. The path is case-sensitive.

所以,你应该写:

Disallow: /header.php

但是,这会阻止 抓取 ,但不一定会阻止 索引 (如果链接到此 URL)。虽然,我怀疑这只是一个 HTML-fragment(?),所以在这种情况下应该阻止抓取。 (但请注意,如果您有许多 includes,那么最好将它们包含在子目录中并简单地阻止子目录。)

在上线前在 Google's robots.txt tester 中测试您的 robots.txt 文件。