Nginx Rewrite Apache?

Francis Daly francis at
Tue Apr 12 02:15:32 MSD 2011

On Mon, Apr 11, 2011 at 05:59:01PM -0400, Adrian Janeczek wrote:

Hi there,

> dosen't  work
> rewrite >
> rewrite "^[A-Z]{3}[a-z]{2}\d{4}[a-z]{3}\d{4}[A-Z]{2}[a-z]\d/(.+)$"
> files/$1;

The nginx debug log is usually good.

In this case, you would see something like

"^[A-Z]{3}[a-z]{2}\d{4}[a-z]{3}\d{4}[A-Z]{2}[a-z]\d/(.+)$" does not match "/QJNqq0821sxz7200DAp0/Si.s_sred.iowi.cze.part5.rar", client:, server: , request: "GET /QJNqq0821sxz7200DAp0/Si.s_sred.iowi.cze.part5.rar

In nginx, the request starts with "/", so if you use "^", the next
character must match "/" or the regex won't match.

> i trying this but not work...
> rewrite "([A-Z] {3})([a-z] {2})([0-9] {4})([a-z] {3})([0-9] {4})([A-Z]
> {2})([a-z] {1})([0-9] {1})/(.+)$" /files/$1 last;

This fails to match because the spaces should not be there. The example on
the wiki should probably be fixed, if someone already has a login there?

If you erase the spaces, then the regex does match, but the replacement
$1 is "QJN", because of the parentheses.

Your original rewrite line wrapped in double quotes should work, with
the initial "^" changed to "^/" (and the replacement "files" becoming

Good luck with it,

Francis Daly        francis at

More information about the nginx mailing list