J
J
JunDevTest2018-07-27 17:12:32
Nginx
JunDevTest, 2018-07-27 17:12:32

Need help building a regular expression for Nginx?

Hello. Need help writing a regular expression. Since only the elite can learn this elven magic, I turn to you for help.
Condition:
There is a url:

http://example.com/assets/Irbis/moto/IRBIS%20XR250/DPP_0015-400x400.png
however, there is nothing along that path.
There is a way:
$document_root/image/data/Irbis/moto/IRBIS%20XR250/DPP_0015.png
here lies the image.
Task:
Need to address
http://example.com/assets/Irbis/moto/IRBIS%20XR250/DPP_0015-400x400.png
there was an internal redirect to
$document_root/image/data/Irbis/moto/IRBIS%20XR250/DPP_0015.png
.
Note:
Url can be like:
http://example.com/assets/(.*)/(.*)/(.*)/(.*)-400x400.png
(the number of folders in the path after assets can be anything, the file extension is (png|jpg) ).
Please issue the answer as a condition for the Nginx config.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Danila Vershinin, 2018-07-27
@dvershinin

rewrite "^/assets/((?:[\s\w]+/)+)([\s\w]+)-400x400\.(png|jpg)" /image/data/$1$2.$3 last;

Checking https://regex101.com/r/9W8xfz/2

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question