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!
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
Here was the solution I eventually came up with, taking from another answer here I found, and modifying its regex, this is currently working for out deployment needs.
#modify query string condition here to suit your needs
RewriteCond %{HTTP_HOST} ^(.*).info [NC]
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
Related
I've an apache 2.4 on a redhat server and I create an http-header in the httpd.conf with this directive:
RewriteEngine on
RewriteCond %{REMOTE_USER} (.*)
RewriteRule .* - [E=X_REMOTE_USER:%1]
RequestHeader set SM_USER %{X_REMOTE_USER}e
the SM_USER header is correctly created but is with domain (utente#domain.com).
I would like to remove the #domain.com using a sort of substring (even creating another header). which syntax I should to use?
thanks
I've found the solution using the regular expression:
RequestHeader set SM_USER %{X_REMOTE_USER}e
RequestHeader edit SM_USER (?=#)(\S+)
Question 1
I currently use the following to noindex a site in htaccess
Header set X-Robots-Tag "noindex, follow"
I have tried all sorts of ways to noindex a pattern and am lost which is why I need help from you experts.
I would like to noindex /tags/ and /s/ and all pages within those categories.
Question 2
I also have another question which is related so I'll ask here instead of posting another question.
I have a number of aliases on a server and one htaccess file. How would I noindex a single URL such as https://www.website.com and allow the others to be indexed?
Can you help?
Use something like
<IfModule mod_headers.c>
<IfModule mod_setenvif.c>
SetEnvIf Request_URI "(*\/tags\/*|*\/p\/*)" x_tag=yes
Header set X-Robots-Tag "noindex, follow" env=x_tag
</IfModule>
</IfModule>
Having issues setting up a generic Allow Origin for any subdomain in my .htaccess file. The following works for a singular subdomain:
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin http://subdomain.website.com
</IfModule>
But what I am looking for is something similar to this:
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin {ANY SUBDOMAIN}.website.com
</IfModule>
I have tried using a simple *.website.com wildcard, but that does not seem to work. Do you have to specify exactly what is coming in?
If you're looking to do it for whatever subdomain was being requested, try the following:
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin %{HTTP_HOST}
</IfModule>
If you need something more advanced, use mod_rewrite to set an environment variable and then refer to it using %{variable_name}e
I have 2 domains pointing to the same folder,
I need to put up a .htaccess file to change cache behaviour on the first domain.
Please don't suggest to edit the server's vhost configuration, this question is specifically for .htaccess.
Something like:
<Match http://domain1.test.com>
Header unset ETag
</Match>
You can try this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain1\.test\.com$ [NC]
RewriteRule ^ [L,E=TESTDOMAIN:1]
# Do not use etags for cache validation.
Header unset ETag env=TESTDOMAIN
# for older Apache versions
Header unset ETag env=REDIRECT_TESTDOMAIN
I need to take a parameter from the query string and set it in the referrer header in the Apache configuration file.
Do you know if this is possible?
I'm able to do the same with the cookies but I need to do it using the query string.
setEnvIfNoCase ^Cookie$ "(referrer=\w*:\/\/\w*)" HTTP_MY_COOKIE=$1
setEnvIfNoCase HTTP_MY_COOKIE "(http:\/\/.*\.\w*)" REFERRER=$1
RequestHeader set Referer %{REFERRER}e
Regards
The solution was quite simple.
setEnvIfNoCase or setEnvIf can't use the query string so is not possible to use the same trick i used for the cookies, the solution is a combination of RewriteCond with RewriteRule like in the example below:
RewriteCond %{QUERY_STRING} referrer=(.*)
RewriteRule ^/ - [env=REFERRER:%1]
RequestHeader set Referer %{REFERRER}e
i answered to my question so another user (if exist) with the same question can find an starting point.