Search code examples
apache.htaccessrobots.txtnofollownoindex

Htaccess no-follow no-index based on domain ending


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!


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