NGINX - rewrite rule with regular expression
<p>I have an url ex. <code>www.something.com/cdn/util/sacle/180/180/......</code> I need to rewrite it to the <code>www.something.com/cdn/_util/scale.php/180/180....</code> How can I do it in nginx? My solution now: </p>

<pre><code>location /cdn/ {
  rewrite ^/util/scale(.*)$ /_util/scale.php/$1 break;
}
</code></pre>

<p>But it is not a good solution for me, because I have some other rewrite rule: </p>

<pre><code>location /serve {
rewrite ^/serve(.*)$ /_util/serve.php/$1 break;
}
location /upload {
rewrite ^/upload(.*)$ /_util/upload.php/$1 break;
}
location /delete {
rewrite ^/delete(.*)$ /_util/delete.php/$1 break;
}
location /copy {
rewrite ^/copy(.*)$ /_util/copy.php/$1 break;
}
location /move {
rewrite ^/move(.*)$ /_util/move.php/$1 break;
}
location /util {
rewrite ^/util/placeholder(.*)$ /_util/placeholder.php/$1 break;
rewrite ^/util/thumb(.*)$ /_util/thumb.php/$1 break;
rewrite ^/util/scale(.*)$ /_util/scale.php/$1 break;
rewrite ^/util/marker(.*)$ /_util/marker.php/$1 break;
}
</code></pre>

<p>I think it is possible in one line too. And the php got the parameters from the url. Which is now working, if I write the url like this: </p>

<pre><code>http://cdn-staging.something.com/util/scale/180/180/dev-employer-images/iamge.jpg
</code></pre>

<p>It is create this: </p>

<pre><code>http://cdn-staging.something.com/_util/scale.php/180/180/dev-employer-images/iamge.jpg
</code></pre>

<p>But it is under Apache, and I need to make it to nginx. </p>