how to fix the rewrite rule?

Francis Daly francis at daoine.org
Thu Jul 19 08:48:41 UTC 2012


On Thu, Jul 19, 2012 at 04:32:47AM -0400, 21andy wrote:

Hi there,

> this works fine
> rewrite "^/([a-f0-9]{2})([a-f0-9]{18})\.(jpg|png|gif)$"
> /test.php?a=$1&b=$2&c=$3 last;
> 
> open /a669164f02f6fdc18f.jpg
> 
> test.php would output
> Array ( [a] => ad [b] => a669164f02f6fdc18f [c] => jpg )

Really?

Your url has 18 hex characters. Your rewrite rule will only match if
there are 20. And "[a] => ad" doesn't appear anywhere in your url.

> but this DO NOT WORK
> rewrite "^/([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{14})\.(jpg|png|gif)$"
> /test.php?a=$1&b=$2&c=$3 last;
> it return 404 error

Here your rewrite rule will only match if there are 18 hex characters.

I expect 

[a] => a6 [b] => 69 [c] => 164f02f6fdc18f

> how can i fix this?

Be consistent.

How long is the url you want to test? Make sure you match exactly that
many characters in your rewrite rule.

	f
-- 
Francis Daly        francis at daoine.org



More information about the nginx mailing list