Goal: I'm trying to set two headers via htaccess:
X-Robots-Tag: noindex, nofollow
Location: http://example.com/foo
PoC: In PHP one could do this which works well:
header( "X-Robots-Tag: noindex, nofollow", true );
header( "Location: " . $url, 302 );
Problem: In my .htaccess
file I have this:
# Do not let robots index anything from /out/
RewriteCond %{REQUEST_URI} ^/?out/?
Header set X-Robots-Tag "noindex, nofollow"
...
# Redirect /out/example/ type links
RewriteRule ^/?out/example/(.*)$ "http://example.com/$1" [R=302,L]
I'm sure there is a simple mistake somewhere that I'm not seeing, but if I inspect the headers of, say, http://localhost/out/example/foo, the Location
header is set, but the X-Robots-Tag
is not.
HTTP/1.1 302 Found
Date: Wed, 08 Jun 2016 23:59:18 GMT
Content-Type: text/html; charset=iso-8859-1
Transfer-Encoding: chunked
Connection: close
Location: http://example.com/foo
...
However, triggering a 404 (e.g. http://localhost/out/404) will set the appropriate header:
HTTP/1.1 404 Not·Found
Date: Wed, 08 Jun 2016 23:56:19 GMT
Content-Type: text/html
Transfer-Encoding: chunked
Connection: close
Vary: Accept-Encoding,User-Agent
X-Robots-Tag: noindex, nofollow <--- set
...
Where is the problem?
always
keyword when setting the header - otherwise, Apache should only set it on 2xx responses. So tryHeader always set ...
– Embracealways
beforeset
in theHeader
directive.Header always set X-Robots-Tag "noindex, nofollow"
– Embrace