문제

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!

도움이 되었습니까?

해결책

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

다른 팁

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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top