4

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

例如,基于此资源http://code.google.com/web/controlcrawlindex/docs/robots_meta_tag.html在标题为“X-Robots-Tag 与 Apache 的实际实现”部分下,它说以下 .htaccess 文件指令可以使用:

<Files ~ "\.pdf$">
  Header set X-Robots-Tag "noindex, nofollow"
</Files>

我正在寻找类似的东西:

<QueryString ~ "m=_!">
  Header set X-Robots-Tag "noindex, nofollow"
</QueryString>

这样,以下 URL 就不会被搜索引擎索引:

http://domain.com/?m=_!ajax_html_snippet

任何提示/提示/线索将不胜感激。谢谢。

4

1 回答 1

7

您可以在 .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
于 2012-01-10T16:33:02.960 回答