2012-10-17 29 views
0

我已經在我的.htaccess文件如下:如何編寫特定子域的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" 

CFhttp://yoast.com/prevent-site-being-indexed/

我的問題然而,相當簡單的也許是:

是否有應用該行只在dev.site.com的一種方式,所以它不會獲得索引?

回答

1

有沒有辦法將這條線只應用於dev.site.com,以便它不被索引?

是的,你需要把Header行放在虛擬主機配置dev.site.com。您無法通過htaccess文件在Header set指令中進行主機檢查。

另一種可能性是,如果你想通過用戶代理阻止機器人,你可以刪除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] 

注意,用戶代理的列表是不完整的。您可以嘗試通過the massive list of User-Agents並查找所有索引機器人,或者至少更受歡迎的機器人。

+0

在提供的鏈接上,他們說:「你的站點在Apache上運行,並且啓用了mod_headers(通常是),你可以將下面的單行添加到你的.htaccess文件中。」 - 我會嘗試第二個選項,因爲我無法訪問共享主機env上的虛擬主機文件。 – MEM

+0

我已經添加了你的最後一個代碼,在htaccess上沒有問題。好。我仍然可以看到在谷歌上搜索時出現的開發者。也許這將是一個時間問題? – MEM

+0

@MEM不知道你如何去除谷歌數據庫中的索引頁面,你必須聯繫他們。但我的猜測是,最終,他們會被刪除,只是因爲他們的網頁的緩存版本變老了。 –