开发者

Check to see if a key exists in a query string - htaccess

开发者 https://www.devze.com 2023-02-05 15:27 出处:网络
my url has query string(s) as follows: ?v=11&ic开发者_开发百科id=someid&near=far OR ?icid=some&v=11&near=far

my url has query string(s) as follows:

?v=11&ic开发者_开发百科id=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

in htaccess, how do I do the following please?

if key "v" exists and the value is not [1-11] redirect to my site

so far I've got the following:

sample url: http://www.mysite.com/2010/01/17/breaking-news/? (one of the above QS's)

RewriteCond %{QUERY_STRING} v

RewriteCond %{QUERY_STRING} v=([^1-11]+)

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

Any help on this is much appreciated.

Thanks,

L


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


Here's my attempt:

#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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号