【问题标题】:How to remove subdomain from google index, which links to the main domain如何从链接到主域的谷歌索引中删除子域
【发布时间】:2013-02-09 19:41:15
【问题描述】:

谁能告诉我如何从谷歌索引中删除子域,它链接到主域。

假设我的域是 www.myweb.com,我的子域是 cdn.myweb.com。现在这里子域的文档根与主域相同。所以我不能使用robot.txt来停止谷歌索引,因为它也会删除索引主域链接。

我也在 google、bing 和 stackoverflow 上搜索,但我找不到这个问题的完美答案。你有什么解决办法吗?

【问题讨论】:

    标签: subdomain cdn google-index


    【解决方案1】:

    您可以为此目的使用动态 robots.txt。 像这样的...

    httpd.conf (.htaccess):

    RewriteRule /robots\.txt$ /var/www/myweb/robots.php
    

    robots.php:

    <?php
    header('Content-type: text/plain');
    
    if($_SERVER['HTTP_HOST']=='cdn.myweb.com'){ 
        echo "User-agent: *\n";
        echo "Disallow: /\n";
    }else{              
        include("./robots.txt");    
    }
    

    【讨论】:

      【解决方案2】:

      我正在使用 nginx,并且在同一个服务器块中有多个子域。我希望将 www 子域包含在 google 的索引中,并将其余子域排除在外。

      首先,在我的 nginx 配置的服务器块中,我添加了以下内容,以便根据域在 /robots.txt 提供 2 个不同的文件。

      location ~ /robots.txt {
          if ($host = 'www.example.com') {
            rewrite ^/robots\.txt /robots.www.txt last;
          }
        }
      

      然后在我网站的根目录下,有以下2个文件:

      • robots.txt 阻止抓取,是所有子域的默认设置
      # Do not crawl subdomain
      User-Agent: *
      Disallow: /
      
      • robots.www.txt 允许抓取所有网站,并且仅在 www.example.com/robots.txt 提供
      User-agent: *
      Disallow:
      

      【讨论】:

      • 如何为托管在 IIS 服务器上的站点完成类似的操作?
      【解决方案3】:

      首先要添加 robots.txt,但在我的情况下,由于我的页面已经使用 CDN 子域编入索引,因此对于机器人来说为时已晚。我发现最好的方法是转到 Google 网站管理员工具,添加我的 cdn 域 (cdn.mysite.com)。然后转到 Google index -> Remove URLs 并删除 / url。过了几天才生效。

      【讨论】:

        猜你喜欢
        • 2011-04-24
        • 1970-01-01
        • 1970-01-01
        • 2019-04-29
        • 1970-01-01
        • 1970-01-01
        • 2012-01-22
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多