【问题标题】:How to set the X-Robots-Tag HTTP header via .htaccess file based on URL query string如何根据 URL 查询字符串通过 .htaccess 文件设置 X-Robots-Tag HTTP 标头
【发布时间】:2012-02-07 00:52:21
【问题描述】:

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

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

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

我正在寻找类似的东西:

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

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

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

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

【问题讨论】:

    标签: .htaccess http-headers query-string nofollow noindex


    【解决方案1】:

    您可以在 .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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-01-17
      • 2022-09-24
      • 2020-08-06
      • 2017-12-21
      • 1970-01-01
      • 1970-01-01
      • 2011-01-09
      相关资源
      最近更新 更多