Question

I have this url:

http://127.0.0.1:8085/test2/Y2hpc3Rh?sx=MTU5OQ==&sy=MTk4&sz=MTg=

and i want to rewrite it to:

/tms/$1/$2/$3/$4.png;

I have this regex:

rewrite /[\w]+/([\w\d]*)?[\w]+[\w]+=([\w\d=]*) /tms/$1/$2.png;

it should work like: /tms/Y2hpc3Rh/MTU5OQ.png but it doesn't. Nginx can not find the groups. What is the problem here?

Was it helpful?

Solution

Try this:

rewrite ^/\w+/(\w*)/?$ /tms/$1/$arg_sx/$arg_sy/$arg_sz.png;

Nginx doesn't include the query-string in the match for rewrite. You can access the parameters by name via $arg_name.

\w is equivalent to [A-Za-z0-9_], so it includes digits.

OTHER TIPS

untested

http://[^/]+/[^/]+/([^?]+)[^=]+=([^=]+)=.* 

/tms/$1/$2.png
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top