Thursday, March 22, 2018

htaccess header for specific domain?

Leave a Comment

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.

2 Answers

Answers 1

@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 

Answers 2

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 
If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment