0

我的 .htaccess 文件中有以下内容:

Options +FollowSymlinks
#+FollowSymLinks must be enabled for any rules to work, this is a security 
#requirement of the rewrite engine. Normally it's enabled in the root and we 
#shouldn't have to add it, but it doesn't hurt to do so.

RewriteEngine on
#Apache scans all incoming URL requests, checks for matches in our #.htaccess file 
#and rewrites those matching URLs to whatever we specify.

#allow blank referrers.
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?site.com [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?site.dev [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?dev.site.com [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ - [NC,F,L]

# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d


# otherwise forward it to index.php
RewriteRule . index.php

site.com 是生产站点。

site.dev 是一个本地主机开发环境。

dev.site.com 是我们进行现场测试的子域。

我知道这将避免网站被索引:

Header set X-Robots-Tag "noindex, nofollow"

参看http://yoast.com/prevent-site-being-indexed/

然而,我的问题可能相当简单:

有没有办法只在 dev.site.com 上应用这条线,这样它就不会被索引?

4

1 回答 1

1

有没有办法只在 dev.site.com 上应用这条线,这样它就不会被索引?

是的,您需要将该Header行放在 vhost 配置中dev.site.com。您无法Header set从 htaccess 文件中将主机检查绑定到指令。

另一种可能性是,如果您想通过用户代理阻止机器人,您可以删除Header set并添加一些规则:

# request is for http://dev.site.com
RewriteCond %{HTTP_HOST} ^dev.site.com$ [NC]
# user-agent is a search engine bot
RewriteCond %{HTTP_USER_AGENT} (Googlebot|yahoo|msnbot) [NC]
# return forbidden
RewriteRule ^ - [L,F]

请注意,用户代理列表并不完整。您可以尝试浏览大量用户代理列表并查找所有索引机器人,或者至少查找更受欢迎的机器人。

于 2012-10-17T21:41:54.723 回答