"[emerg]: pcre_compile() failed: missing terminating ]" in rewrite rule.

Maxim Dounin mdounin at mdounin.ru
Thu May 13 01:48:19 MSD 2010


Hello!

On Wed, May 12, 2010 at 11:09:12PM +0200, Grzegorz Sienko wrote:

> Hi.
> 
> I'm trying to do some rewrite. My url is:
> http://domain.tld/stream/file/{username}{crc_username}{hash-file}.{extension}
> and I'm want it to rewrite it to different location, where files physically are.
> 
>         location ^~ /stream/file/ {
>                 rewrite
> "([a-f0-9]{8})([a-f0-9]{8})([a-f0-9]{40})(\.[^\.\/\\]*)$?"

- "([a-f0-9]{8})([a-f0-9]{8})([a-f0-9]{40})(\.[^\.\/\\]*)$?"
+ "([a-f0-9]{8})([a-f0-9]{8})([a-f0-9]{40})(\\.[^./\\\\]*)?$"

nginx uses '\' as escape character in it's config syntax, and it 
should be doubled if you want to pass it literally.

(and you don't need '\' before '.' in character group; and don't 
need '\' before '/'; and '?' can't follow '$')

[...]

> and while testing configuration I got error:
> [emerg]: pcre_compile() failed: missing terminating ] for character
> class in "([a-f0-9]{8})([a-f0-9]{8})([a-f0-9]{40})(\.[^\.\/\]*)$?"
> 
> And I don't see why I missed one ] ? When I add ] to the end I got
> error: pcre_compile() failed: missing terminating ).

Regexp printed in error message is a hint.

Maxim Dounin



More information about the nginx mailing list