Q
Q
QQ2016-05-22 21:09:22
Nginx
QQ, 2016-05-22 21:09:22

How to return images by ID and any name?

Hello.
In general, the task is this: on the server, all the pictures are numbered and lie in the /img folder, how to make it so that when requested:

domain.com/custom/url/luboe_nazvanie_pic12975_etc.jpg

gave a picture from the /img folder
/img/12975.jpg
UPD: Nginx server.
I don’t understand how to access a specific picture with an ID?
if ($uri ~ pic(\d+)) {
            set $pic_id $1; 
}
    
location /custom/url {
            root /img;
            access_log off;
            autoindex off;
            expires 30d;
            add_header Cache-Control "public, no-transform";
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Savostin, 2016-05-22
@botaniQQQ

rewrite "^\/custom\/url\/.*([0-9]+).*\.jpg$"       "/img/$1.jpg" break;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question