Question

I am trying to make our htaccess file as dynamic as possible, and wish to allow indexing of our .com site, but not of our .info site. We are using the same htaccess on both servers.

Is there an easy way to conditionally decide this in htaccess?

something like this?

If the domain does not end with "." and 3 letters then noindex nofollow?

RewriteCond %{HTTP_HOST} !^[^.]+\.[^.]{3}$
Header set X-Robots-Tag "noindex, nofollow"

Thanks for any input/help!

Was it helpful?

Solution

You can take help of mod_setenvif here:

# make sure it is not .com
SetEnvIf Host \.[^.]{4,}$ ROBOTAG
# set header if ROBOTAG is set
Header set X-Robots-Tag "noindex, nofollow" env=ROBOTAG

OTHER TIPS

Here was the solution I eventually came up with, taking from another answer here I found, and modifying its regex, this is currently working for out deployment needs.

#modify query string condition here to suit your needs
RewriteCond %{HTTP_HOST} ^(.*).info [NC]
RewriteRule .* - [E=MY_SET_HEADER:1]

#if MY_SET_HEADER is present then set header
Header set X-Robots-Tag "noindex, nofollow" env=MY_SET_HEADER
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top