7

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

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

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

谢谢

4

2 回答 2

15

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

除了要求搜索引擎阻止除 之外的所有页面之外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">

另见谷歌关于 rel="canonical" 的文章

于 2010-10-05T06:53:19.717 回答
0

仅用于 .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]
于 2019-03-14T19:56:31.407 回答