4

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.

1 Answer 1

7

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.