This apache configuration can be added to the .htaccess file of a site to automatically keep staging and development versions from being indexed by Google and other search engines. No more worrying about whether or not noindex
is keeping live sites from being crawled by search engines!
# Check HTTP_HOST variable and set noindex, nofollow for hosts other than the live site
<IfModule mod_rewrite.c>
RewriteCond %{HTTP_HOST} ^domain\.com$
RewriteRule ^ - [E=live_env:true]
</IfModule>
<Files ~ ".*">
Header set X-Robots-Tag "noindex, nofollow" env=!live_env
</Files>