2011年2月7日星期一

URI pattern baffling problem

Hi,

I am trying to work out a regular expression. What I am looking for is to redirect any request that does not match a specific URI pattern.

The exact pattern is "documents/{VAR1}/pages/{VAR2}/items/{VAR3}" where {VAR1} /{VAR2} /{VAR3} is a random chain of 36 characters made of A-Z, a-z, 0-9 and – (hyphen). Text is not case sensitive and the position of hyphens is fixed. Would be great if I could also work trailing double-slash.

So far what I have generated is:

if ($request_uri !~* "^documents/([a-z0-9\-]{36})pages/([a-z0-9\-]{36})items/([a-z0-9\-]{36})$" ) {
   rewrite ^ http://www.google.com/ permanent;
}

Regular expression is not really my cup of tea, so any hint is most welcome!

Gregory

没有评论:

发表评论