我可以'无索引,在.htaccess中使用x机器人关注'特定页面吗?
我已经找到了一些没有索引文件类型的说明,但我找不到单页索引的说明,到目前为止我尝试过的都没有用。
这是我正在寻找noindex的页面:
http://www.examplesite.com.au/index.php?route=news/headlines
这是我到目前为止所尝试的:
<FilesMatch "/index.php?route=news/headlines$">
Header set X-Robots-Tag "noindex, follow"
</FilesMatch>
感谢您的时间。
答案 0 :(得分:9)
似乎无法匹配.htaccess文件中的请求参数。以下是您可以匹配的内容列表:http://httpd.apache.org/docs/2.2/sections.html
在脚本中执行它会容易得多。如果您在PHP上运行,请尝试:
header('X-Robots-Tag: noindex, follow');
您可以轻松地在$ _GET,REQUEST_URI等上构建条件。
答案 1 :(得分:4)
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
FilesMatch适用于(本地)文件,而不是网址。所以它会尝试只匹配url的/index.php部分。 <location>
会更合适,但据我可以从文档中读到,此处不允许查询字符串。所以我最终得到了上述解决方案(我真的很喜欢这个挑战)。虽然php会是更明显的地方,但这取决于你。
解决方案当然需要mod_rewrite和mod_headers。
答案 2 :(得分:0)
请注意,您需要启用mod_headers模块来设置标题。
虽然像其他人说的那样,但使用php标签似乎更好。这不起作用吗?
答案 3 :(得分:0)
根据Google的说法,语法会略有不同:
<Files ~ "\.pdf$">
Header set X-Robots-Tag "noindex, nofollow"
</Files>
https://developers.google.com/webmasters/control-crawl-index/docs/robots_meta_tag