【问题标题】:How to block search engines from indexing all urls beginning with origin.domainname.com如何阻止搜索引擎索引以 origin.domainname.com 开头的所有 url
【发布时间】:2011-04-21 03:32:02
【问题描述】:

我有 www.domainname.com、origin.domainname.com 指向同一个代码库。有没有办法,我可以防止 basename origin.domainname.com 的所有 url 被索引。

robot.txt 中是否有一些规则可以做到这一点。两个网址都指向同一个文件夹。 另外,我尝试在 htaccess 文件中将 origin.domainname.com 重定向到 www.domainname.com,但它似乎不起作用..

如果有人遇到过类似问题并可以提供帮助,我将不胜感激。

谢谢

【问题讨论】:

    标签: .htaccess url-rewriting robots.txt


    【解决方案1】:

    仅用于 .htaccess:

    RewriteEngine on
    RewriteCond %{HTTP_USER_AGENT} AltaVista [OR]
    RewriteCond %{HTTP_USER_AGENT} Googlebot [OR]
    RewriteCond %{HTTP_USER_AGENT} msnbot [OR]
    RewriteCond %{HTTP_USER_AGENT} Slurp
    RewriteRule ^.*$ "http\:\/\/htmlremix\.com" [R=301,L]
    

    【讨论】:

      【解决方案2】:

      您可以将robots.txt 重写为另一个文件(让我们将此命名为“robots_no.txt”,其中包含:

      User-Agent: *
      Disallow: /
      

      (来源:http://www.robotstxt.org/robotstxt.html

      .htaccess 文件如下所示:

      RewriteEngine On
      RewriteCond %{HTTP_HOST} !^www.example.com$
      RewriteRule ^robots.txt$ robots_no.txt
      

      为每个(子)域使用自定义 robots.txt:

      RewriteEngine On
      RewriteCond %{HTTP_HOST} ^www.example.com$ [OR]
      RewriteCond %{HTTP_HOST} ^sub.example.com$ [OR]
      RewriteCond %{HTTP_HOST} ^example.com$ [OR]
      RewriteCond %{HTTP_HOST} ^www.example.org$ [OR]
      RewriteCond %{HTTP_HOST} ^example.org$
      # Rewrites the above (sub)domains <domain> to robots_<domain>.txt
      # example.org -> robots_example.org.txt
      RewriteRule ^robots.txt$ robots_${HTTP_HOST}.txt [L]
      # in all other cases, use default 'robots.txt'
      RewriteRule ^robots.txt$ - [L]
      

      您也可以使用&lt;link rel="canonical"&gt;,而不是要求搜索引擎屏蔽除www.example.com 以外的所有页面。

      如果http://example.com/page.htmlhttp://example.org/~example/page.html 都指向http://www.example.com/page.html,则将下一个标签放入&lt;head&gt;

      <link rel="canonical" href="http://www.example.com/page.html">
      

      另见Googles article about rel="canonical"

      【讨论】:

      • Lekensteyn,看起来不错。但是,我有一个小小的疑问。是否可以根据 url 分配不同的 robots.txt 文件。一直找不到这样的规则。如果你能指出我这样的 tuts,那会很有帮助..谢谢..
      • “基于 url”是什么意思?如果您的意思是“域”,请查看上面的示例。重写指南:httpd.apache.org/docs/current/rewrite/rewrite_intro.html。为每个域实现不同robots.txt 的另一种方法是使用服务器脚本,例如 PHP。
      • @Lekensteyn 域可以,但是如何防止文件夹使用 .htaccess(没有 robots.txt)?
      • @RaviG。你能改写一下并提出一个新问题吗?目前还不清楚你在问什么。您的意思是“如何防止搜索引擎索引 /admin/ 等文件夹?”
      • @Lekensteyn 这是我的错误和更狡猾的问题。 ;我可以阻止仅使用 .htaccess 编制索引(没有 robots.txt 文件)吗?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多