htaccess header for specific domain?

↘锁芯ラ 提交于 2020-01-01 10:13:09

问题


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.


回答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



回答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


来源:https://stackoverflow.com/questions/49250244/htaccess-header-for-specific-domain

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!