
我有以下 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
# 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]
我不希望透過谷歌搜尋或類似方式公開 dev.site.com。
我已經放置了這個。我應該等待嗎?或者還有什麼我該做的嗎?
答案1
.htaccess 並不是真正阻止網站出現在 Google 搜尋索引中的地方。 機器人.txt是為此目的而設計的方法之一。
放置這個:
User-agent: *
Disallow: /
在 dev.site.com 根目錄中名為「robots.txt」的檔案中應該會阻止它出現。
或者你可以包括一個元標籤在您不想出現的頁面中,例如:
<meta name="robots" content="noindex">
或者如果是僅有的Google 提示您不希望將您的頁面編入索引,但允許您使用其他機器人:
<meta name="googlebot" content="noindex">
在開發/生產類型場景中,這樣做的缺點是您必須採取一些措施來確保這些標籤不會出現在您的生產代碼中(假設您做希望 Google 為您的生產伺服器建立索引)。