0

Let's say a user tries to access a given image on my website using the following URL: http://www.mywebsite.com/random/image1.jpg?someParam=100

I need a rewrite rule to this, removing the 'random' node from the path:

http://www.mywebsite.com/image1.jpg?someParam=100

I have found similar question here But in my case, the 'random' changes and I don't know how many such folders are there. How do I do it. ?

  • Can you describe the first URL as a regular expression? In which case, use it in a `rewrite ... last` statement. See [this document](http://nginx.org/en/docs/http/ngx_http_rewrite_module.html#rewrite) for details. – Richard Smith Oct 30 '16 at 18:06

1 Answers1

0

You probably don't want this exactly, but here is a starting point:

server {

    ...

    rewrite ^/[a-z]+/(.*)$ $1 last;

}

That will replace anything in a "directory" that is made up of letters, e.g. random/image.php -> image.php, img/test.png -> test.png

tanerkay
  • 261
  • 1
  • 9