Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

htaccess header for specific domain?

Tags:

.htaccess

I have three environments:

env.com
env-uat.com
env-pre.com

All three pages run the same code. I want env-uat.com and env-pre.com to both get this in the htaccess:

Header set X-Robots-Tag "noindex, nofollow"

This will effectively completely unindex these pages, including PDF files etc. But I don't want to affect env.com.

How can I make the Header X-Robots-Tag only be added for env-uat.com and env-pre.com and NOT env.com?

** UPDATE **

From what I could find so far, it would seem you can only do something like this:

SetEnvIf Request_URI "^/privacy-policy" NOINDEXFOLLOW
Header set X-Robots-Tag "noindex, follow" env=REDIRECT_NOINDEXFOLLOW

But this makes it specific to a PAGE. I want it specific to a DOMAIN.

like image 646
coderama Avatar asked Mar 13 '18 07:03

coderama


2 Answers

@Starkeen was right up to here :

SetEnvIf host ^(env-uat\.com|host2\.com)$ NOINDEXFOLLOW

So , you could include the domains that you want to be involved in this Env like this :

SetEnvIf host ^(env-uat|env-pre)\.com NOINDEXFOLLOW

Then you should attach the Env with same name like this :

Header set X-Robots-Tag "noindex, follow" env=NOINDEXFOLLOW

Not like this :

Header set X-Robots-Tag "noindex, follow" env=REDIRECT_NOINDEXFOLLOW

The line above will look to Env its name is REDIRECT_NOINDEXFOLLOW not NOINDEXFOLLOW and it is diffrent case from this question X Robots Tag noindex specific page That was about matching against Request_URI and for special case .

So , the code should look like this :

SetEnvIf host ^(env-uat|env-pre)\.com NOINDEXFOLLOW
Header set X-Robots-Tag "noindex, follow" env=NOINDEXFOLLOW
like image 191
Mohammed Elhag Avatar answered Nov 19 '22 16:11

Mohammed Elhag


You can match against Host header using SetEnvIf directive.

To make the Header X-Robots-Tag only available for a specific host ( env-uat.com ) you could use something like the following :

SetEnvIf host ^env-uat\.com$ NOINDEXFOLLOW
Header set X-Robots-Tag "noindex, follow" env=REDIRECT_NOINDEXFOLLOW

To make this available for multiple hosts ,you could use the following :

SetEnvIf host ^(env-uat\.com|host2\.com)$ NOINDEXFOLLOW
Header set X-Robots-Tag "noindex, follow" env=REDIRECT_NOINDEXFOLLOW
like image 39
Amit Verma Avatar answered Nov 19 '22 18:11

Amit Verma