Hide a path node in nginx

dioo asked:

I have the following url:

http://example.com/dr/2015/10/pic.jpg

where 2015/10/pic.jpgis dynamic: 2015 is the year, 10 is the month number and pic.jpg a file name. Every time an image is sent, the year and month folders are created as the current date.

I would like to remove the node “dr” of the url, like the example below:

http://example.com/2015/10/pic.jpg

I found this question, which is the closest to what I need: http://superuser.com/questions/435916/nginx-rewrite-rule-to-remove-path-node

My answer:


You could just add it to your try_files. This is the simplest and will perform better than a rewrite. For example:

try_files /dr$uri $uri ....the rest of it...

View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.