Prevent cookieless subdomain for static assets from being indexed by search engines

五迷三道 提交于 2019-12-13 18:16:01

问题


I've created a new subdomain for all static assets (static.example.com) by creating a new A record and pointing it at the same server with a new IP address and then creating a virtual host with the same DocumentRoot as the main www.example.com site. We've pointed all references for static resources to the static subdomain however all website resources can be accessed via either static.example.com or www.example.com.

The problem is that Google has begun to index html files on the static.example.com subdomain. What would be the best way to prevent Google from indexing files on this domain?


回答1:


There are several ways to do this. One is using robots.txt

Create a static.example.com.robots.txt file in the root directory and put the following in it (can't use robots.txt, because its shared with other domains).

This will disallow all spiders incl GoogleBot

User-agent: *
Disallow: /

To ensure that this is served only from the static.example.com site add the following rule to your .htaccess in the root folder of your site.

RewriteEngine On
RewriteBase /


#if request is on static.example.com
RewriteCond %{HTTP_HOST} ^static\.example\.com$ [NC]
#serve robots.txt from static.example.com.robots.txt
RewriteRule ^(robots\.txt)$ %{HTTP_HOST}.$1 [L,NC]


来源:https://stackoverflow.com/questions/8945617/prevent-cookieless-subdomain-for-static-assets-from-being-indexed-by-search-engi

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!