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.
#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
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
Related
I use
Header set X-Frame-Options SAMEORIGIN
in .htaccess
But i would like to have 1 html page that isn't blocked when shown in iframe on other websites.....
How can i make 1 exception?
The Header directive provides an additional argument that allows you to set the header conditionally based on whether an environment variable is set or not.
You could then set an env var when this one URL is requested. And only allow the header to be set when the env var is not set.
For example:
SetEnvIf Request_URI "^/one-page-not-blocked\.html$" DO_NOT_BLOCK
Header set X-Frame-Options SAMEORIGIN env=!DO_NOT_BLOCK
The above SetEnvIf directive sets the env var DO_NOT_BLOCK to the value 1 when the regex matches the requested URL.
The env=!DO_NOT_BLOCK argument is successful when the env var is not set (denoted by the ! prefix).
This method allows you to add additional URLs to not block by simply adding more SetEnvIf directives.
I have to set different Env for different subdomains. For example, domain/subdomain1 MAGE_RUN_CODE=mobile_en, but domain/subdomain2 MAGE_RUN_CODE=global
This code works:
SetEnvIf Host .*mydomain.net.* MAGE_RUN_CODE=mobile_en
But this code doesn't work
SetEnvIf Host .*mydomain.net/ahava-m1-mobile.* MAGE_RUN_CODE=mobile_en
How should I change second code to make it working?
As explained in the comments above, HOST keyword is used for http host headers ie example.com . Since your url contains a path segment /ahava-m1-mobile you need to match against Request-uri variable.
SetEnvIF request_uri ^/ahava-m1-mobile MAGE_RUN_CODE=mobile_en
Firstly I tried adding multiple ifmodule but it does not work.
<ifModule mod_headers.c>
Header set Access-Control-Allow-Origin: http://domainurl1.com
</ifModule>
<ifModule mod_headers.c>
Header set Access-Control-Allow-Origin: http://domainurl2.com
</ifModule>
When try to add multiple ifmodule only last one(http://domainurl2.com) works others not.
then I try following code it works but i think it is not secure to allow everyone
<ifModule mod_headers.c>
Header set Access-Control-Allow-Origin: “*”
</ifModule>
I have 5 domain that i have to allow.
Are there any solutions for adding multiple domains that i want to allow?
Try this if you want a quick fix
<ifModule mod_headers.c>
Header add Access-Control-Allow-Origin "http://domainurl1.com"
Header add Access-Control-Allow-Origin "http://domainurl2.com"
</ifModule>
However, this is not the recommended solution by W3C, instead you should make the server read the Origin header from the client, then compare it to a list of allowed domains and finally send the value of the Origin header back to the client as the Access-Control-Allow-Origin header. Check http://www.w3.org/TR/cors/#access-control-allow-origin-response-hea for more details.
I'm unsure whether the following is correct considering I can't find a web example that targets a file inside a directory.
<FilesMatch "/out/index.php$">
Header set X-Robots-Tag "noindex, nofollow"
</FilesMatch>
is it ok that way or:
<FilesMatch "\out\index.php$">
Header set X-Robots-Tag "noindex, nofollow"
</FilesMatch>
First one is the right one as Apache like Unix systems uses forward slash for paths.
So the right one is:
<FilesMatch "/out/index\.php$">
Header set X-Robots-Tag "noindex, nofollow"
</FilesMatch>
Is it possible to apply HTTP header directives based on the URL's query string using an apache .htaccess?
For example, based on this resource http://code.google.com/web/controlcrawlindex/docs/robots_meta_tag.html under the section titled "Practical implementation of X-Robots-Tag with Apache" it says the following .htaccess file directive can be used:
<Files ~ "\.pdf$">
Header set X-Robots-Tag "noindex, nofollow"
</Files>
I'm looking for something along the lines of:
<QueryString ~ "m=_!">
Header set X-Robots-Tag "noindex, nofollow"
</QueryString>
This way the following URL would NOT get indexed by search engines:
http://domain.com/?m=_!ajax_html_snippet
Any hints/tips/clues would be much appreciated. Thanks.
You can try the following in your .htaccess file
#modify query string condition here to suit your needs
RewriteCond %{QUERY_STRING} (^|&)m=_\! [NC]
#set env var MY_SET-HEADER to 1
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