h-y-b-r-i-d
h-y-b-r-i-d

Reputation: 325

Nginx rule to add x-robots-tag header

I just moved from apache to nginx and cant fathom this rule.

I want to add this header to all pages that include a query string.

add_header X-Robots-Tag "noindex, nofollow";

The apache working rule was.

RewriteCond %{QUERY_STRING} (^|&)(sortOrder|sortField) [NC]
RewriteRule .* - [E=MY_SET_HEADER:1]
Header set X-Robots-Tag "noindex,nofollow" env=MY_SET_HEADER

Thanks in advance.

Upvotes: 27

Views: 39574

Answers (1)

Rafa
Rafa

Reputation: 891

The next line should be in the location block of your nginx config (usually in /etc/nginx/sites-avalable/):

add_header  X-Robots-Tag "noindex, nofollow, nosnippet, noarchive";

Should be nice to check before and after the modification with an:

# service nginx reload

Through this online tool: http://headers.cloxy.net

And it should show:

X-Robots-Tag: noindex, nofollow, nosnippet, noarchive

Upvotes: 54

Related Questions