如何通过基于URL查询字符串的.htaccess文件设置X-Robots-Tag HTTP头

Joh*_*rck 3 .htaccess nofollow noindex http-headers query-string

是否可以使用apache .htaccess基于URL的查询字符串应用HTTP头指令?

例如,根据此资源http://code.google.com/web/controlcrawlindex/docs/robots_meta_tag.html标题为"实际实施X-Robots-Tag with Apache"一节,它说明了以下.htaccess文件指令可以使用:

<Files ~ "\.pdf$">
  Header set X-Robots-Tag "noindex, nofollow"
</Files>
Run Code Online (Sandbox Code Playgroud)

我正在寻找以下内容:

<QueryString ~ "m=_!">
  Header set X-Robots-Tag "noindex, nofollow"
</QueryString>
Run Code Online (Sandbox Code Playgroud)

这样,搜索引擎就不会将以下网址编入索引:

http://domain.com/?m=_!ajax_html_snippet
Run Code Online (Sandbox Code Playgroud)

任何提示/提示/线索将非常感激.谢谢.

Ulr*_*lha 5

您可以在.htaccess文件中尝试以下操作

#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
Run Code Online (Sandbox Code Playgroud)