检查查询字符串中是否存在密钥 - htaccess

时间:2011-01-17 14:03:23

标签: .htaccess

我的网址有查询字符串,如下所示:

?v=11&icid=someid&near=far
OR
?icid=some&v=11&near=far
OR
?icid=some&near=far&v=11
OR
?v=11
OR
There may be more but "v" exists

在htaccess中,我该怎么办呢?

如果存在密钥“v” 和 价值不是[1-11] 重定向到我的网站

到目前为止,我有以下内容:

示例网址:http://www.mysite.com/2010/01/17/breaking-news/? (上述QS之一)

RewriteCond%{QUERY_STRING} v
RewriteCond%{QUERY_STRING} v =([^ 1-11] +)
RewriteRule([1000-9999] +)/([^ /] +)/([^ /] +)/([^ /] +)/?([0-99] +)?$ http://% {HTTP_HOST} /? [R,L]

非常感谢任何帮助。

谢谢,
大号

2 个答案:

答案 0 :(得分:1)

RewriteCond %{QUERY_STRING} v=([^&]+)
RewriteCond %1 !^(?:\d|11)$
RewiteRule ... stuff

答案 1 :(得分:0)

这是我的尝试:

#grab the v parameter, allowing it to appear anywhere within the query string,
#without matching part of another parameter name such as "gov"
RewriteCond %{QUERY_STRING} (?:^|&)v=([^&]*)(?:$|&)

#check if it's NOT set to a digit between 1-11
RewriteCond %1 !^(?:[1-9]|1[01]?)$

#Begin matching anywhere within the requested URL, since there's no leading caret.
#If this should match the beginning, and not somewhere within the middle,
#then add a leading caret.
#The logic is as follows:
#Check if we have a number between 1000 and 9999 followed by a slash;
#then three slash delimited chunks with slashes in between;
#then an optional chunk which, if matched, must begin with a slash, then 
#a number between 0 and 99 (including a leading zero);
#followed by an optional tailing slash;
#followed by the end of the string.
RewriteRule ([1-9]\d{3})/([^/]+)/([^/]+)/([^/]+)(?:/(\d\d?))?/?$ http://%{HTTP_HOST}/? [R,L]

#more rules can go here if we didn't redirect