How to fix the rewrite rule?

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 )

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

how can i fix this?

Posted at Nginx Forum:

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 D. [email protected]

Hello andi,

your solution looks a bit like my question from last
night… i use md5 hash to build my filenames, what
kind of hash do you use? 20 chars look intresing :slight_smile:
are these unique hashes?

Elena

-------- Original-Nachricht --------

Datum: Thu, 19 Jul 2012 04:32:47 -0400 (EDT)
Von: “21andy” [email protected]
An: [email protected]
Betreff: how to fix the rewrite rule?