【问题标题】:How to allow crawlers access to index.php only, using robots.txt?如何使用 robots.txt 只允许爬虫访问 index.php?
【发布时间】:2010-12-10 21:24:30
【问题描述】:

如果我只想让爬虫访问 index.php,这样行吗?

User-agent: *
Disallow: /
Allow: /index.php

【问题讨论】:

  • 我很好奇您为什么要这样做...您不希望爬虫为您网站的更多内容编制索引吗?

标签: seo web-crawler robots.txt


【解决方案1】:

是的,它会起作用的。这是Google Webmaster Tool的测试结果。

Url
http://www.example.org/index.php

Googlebot
Allowed by line 3: Allow: /index.php

Googlebot-Mobile
Allowed by line 3: Allow: /index.php

但是,请记住,如果使用此配置,您的网站主页将不会被抓取,除非使用完整的限定路径访问该页面。 换句话说,http://www.example.org/ 被禁止,http://www.example.org/index.php 被允许。

如果您希望您的主页可以访问,这里有一个更好的文件版本。

User-agent: *
Disallow: /
Allow: /index.php
Allow: /$

【讨论】:

  • 你能解释一下为什么 /$ 起作用,或者它有什么作用吗?
  • /$的解释可以找到here
【解决方案2】:

尝试交换 Disallow / Allow 的顺序:

User-agent: *
Allow: /index.php
Disallow: /

从维基百科查看此信息:

“然而,为了兼容所有 机器人,如果你想允许单 否则不允许的文件 目录,您需要放置 Allow 首先是指令,然后是 禁止,例如:"

http://en.wikipedia.org/wiki/Robots.txt

我仍然不希望它工作太一致

【讨论】:

    【解决方案3】:
    User-agent: *
    
    Allow: /index.php
    Disallow: /
    

    【讨论】:

      【解决方案4】:

      您可以使用Google Robots tool 结帐。我永远不会在 robots 文件中放置任何秘密目录,因为我猜像下面这样的行对于某些蜘蛛来说就像蜂蜜一样。

      Disallow: /secret
      

      【讨论】:

        【解决方案5】:
        User-agent: *
        Allow: /$
        Allow: /index.php
        Allow: /sitemap.xml
        Allow: /robots.txt
        Disallow: /
        
        Sitemap: http://www.your-site-name.com/sitemap.xml
        

        【讨论】:

        • 你能解释一下你的答案吗?
        • $ 表示“行尾”,因此它匹配 whateverdoma.in - 没有任何其他 URL 字符
        猜你喜欢
        • 1970-01-01
        • 2012-04-29
        • 1970-01-01
        • 1970-01-01
        • 2011-06-11
        • 2016-08-06
        • 1970-01-01
        • 2012-08-31
        • 2012-01-07
        相关资源
        最近更新 更多