2010-10-05 100 views
4

我有www.domainname.com,origin.domainname.com指向相同的代码库。有没有办法,我可以阻止basename origin.domainname.com的所有网址被索引。如何阻止搜索引擎索引从origin.domainname.com开始的所有网址

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

如果谁有类似的问题,可以帮助,我将不胜感激。

感谢

回答

11

可以重写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 

使用customiz编辑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] 

不要问搜索引擎阻止超过www.example.com其他网页上的所有网页,你可以使用<link rel="canonical">了。

如果http://example.com/page.htmlhttp://example.org/~example/page.html都指向http://www.example.com/page.html,把下一个标签在<head>

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

参见Googles article about rel="canonical"

+0

Lekensteyn,看起来不错。但是,我有一个小小的怀疑。是否有可能根据url分配不同的robot.txt文件。无法找到这样的规则。如果你能指点我这样的馅饼,这将是有益的..感谢.. – 2010-10-06 03:49:17

+0

你是什么意思'基于URL'?如果你的意思是'域名',看看上面的例子。重写指南:http://httpd.apache.org/docs/current/rewrite/rewrite_intro.html。为每个域实现不同的'robots.txt'的另一种方式是使用serverscript,例如PHP。 – Lekensteyn 2010-10-06 07:21:44

+1

gotchas .. thankees ..! – 2010-10-07 09:10:50