简体   繁体   English

需要定位/禁止robots.txt中的子域

[英]Need to target/disallow subdomains in robots.txt

Good morning. 早上好。

So, I have run into a tricky situation. 因此,我遇到了一个棘手的情况。 My environment is a 2 server mirrored setup. 我的环境是2服务器镜像设置。 I have 2 sub domains to target each server specifically when needed. 我有2个子域,可以在需要时专门针对每个服务器。 I would like to disallow indexing of the 2 sub domains without affecting the www. 我想在不影响www的情况下禁止对2个子域建立索引。

For example, I have sub1.domain.com/sub2.domain.com/www.domain.com. 例如,我有sub1.domain.com/sub2.domain.com/www.domain.com。 They all point to the same web root directory. 它们都指向相同的Web根目录。 Merely saying user agent disallow in robots.txt will not work as it will remove indexing of the www. 仅仅说用户代理禁止robots.txt无效,因为它将删除www的索引。

Please feel free to ask any questions as needed. 请随时问任何问题。

Thanks! 谢谢!

You can place a robots.txt file and name it something like, no-index-robots.txt. 您可以放置​​robots.txt文件,并将其命名为no-index-robots.txt。 You'd just put: 您只需输入:

User-agent: *
Disallow: /

in there. 在那里。 Then in the htaccess file in your document root, add this: 然后在文档根目录的htaccess文件中添加以下内容:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(sub1\.|sub2\.)domain\.com$ [NC]
RewriteRule ^robots\.txt$ /no-index-robots.txt [L]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM