moo*_*bot 6 .htaccess nofollow noindex http-headers x-robots-tag
我可以'无索引,在.htaccess中使用x机器人的特定页面吗?
我已经找到了一些没有索引文件类型的说明,但是我找不到指令来对单个页面进行索引,而我到目前为止所尝试的内容并没有奏效.
这是我正在寻找noindex的页面:
http://www.examplesite.com.au/index.php?route=news/headlines
Run Code Online (Sandbox Code Playgroud)
这是我到目前为止所尝试的:
<FilesMatch "/index.php?route=news/headlines$">
Header set X-Robots-Tag "noindex, follow"
</FilesMatch>
Run Code Online (Sandbox Code Playgroud)
谢谢你的时间.
eis*_*erg 10
似乎无法匹配.htaccess文件中的请求参数.以下是您可以匹配的列表:http://httpd.apache.org/docs/2.2/sections.html
在脚本中执行它会容易得多.如果您正在运行PHP,请尝试:
header('X-Robots-Tag: noindex, follow');
Run Code Online (Sandbox Code Playgroud)
您可以轻松地在$ _GET,REQUEST_URI等上构建条件.
RewriteEngine on
RewriteBase /
#set env variable if url matches
RewriteCond %{QUERY_STRING} ^route=news/headlines$
RewriteRule ^index\.php$ - [env=NOINDEXFOLLOW:true]
#only sent header if env variable set
Header set X-Robots-Tag "noindex, follow" env=NOINDEXFOLLOW
Run Code Online (Sandbox Code Playgroud)
FilesMatch 适用于(本地)文件,而不是 url。所以它会尝试只匹配 url 的 /index.php 部分。<location>会更合适,但据我从文档中看到,这里不允许使用查询字符串。所以我最终得到了上述解决方案(我真的很喜欢这个挑战)。虽然 php 是放置这个的更明显的地方,但这取决于你。
解决方案当然需要 mod_rewrite 和 mod_headers。
| 归档时间: |
|
| 查看次数: |
11322 次 |
| 最近记录: |