htaccess query_string

时间:2012-10-09 17:52:34

标签: regex apache .htaccess mod-rewrite

搜索引擎使用参数

抓取网站
/?p=([0-9]+)
/?cat=([0-9]+)
/?do=([a-z]+)

如何让.htaccess通知搜索引擎这些网页不再存在?

我只有/?page =([0-9] +)

感谢。

我试过

RewriteCond %{QUERY_STRING} ^(p|cat|do)(.*)$
RewriteRule ^$ http://test.com/simple [R=301,L]

http://test.com/?p=23 give me http://test.com/test?p=23 (not http://test.com/test)
http://test.com/?cat=11 give me http://test.com/test?cat=11 (not http://test.com/test)

2 个答案:

答案 0 :(得分:1)

我建议您遵循301(永久重定向)规则:

RewriteCond %{QUERY_STRING} !^page=.*$ [NC]
RewriteRule ^$ http://test.com/test? [R=301,L]

这会将每个/?p=([0-9]+)/?do=([0-9]+)/?foo=([0-9]+)/?bar=([0-9]+)等(除/?page=之外的任何查询字符串)重定向到http://test.com/test { {1}}并删除原始查询字符串(请注意目标网址末尾的R=301)。

答案 1 :(得分:0)

您可以将这些页面添加到robots.txt文件中,以防止编制索引。

然而,在某些地方搜索引擎找到这些链接。您应该确保不在自己的网站上使用它们。

如果网页不再存在,您可能会相应地考虑redirecting(301)。

后者或其中的某些组合应该让你理智。