Is it possible to make this kind of url rewrite?
Request url: https://image.domain.com/listing/1_10_iP2LROSEafC01584630756.jpg Rewrite to: https://image.domain.com/images/i/P/2/L/iP2LROSEafC01584630756.jpg
If /images/i/P/2/L/iP2LROSEafC01584630756.jpg exists in server, it's served, if not then query is redirected to php file /make_image.php
Thank you!
Request url: https://image.domain.com/listing/1_10_iP2LROSEafC01584630756.jpg Rewrite to: https://image.domain.com/images/i/P/2/L/iP2LROSEafC01584630756.jpg
If you mean an external redirect, then this is achieved using the rewrite directive. Place the statement in the server block, or within a location block that handles these kinds of request (i.e. URIs beginning with /listing/ and/or ending with .jpg).
Your question does not state what 1_10_ means, but let's assume that you want the two arbitrary numbers ignored.
For example:
rewrite ^/listing/\d+_\d+_(.)(.)(.)(.)(.*)$ /images/$1/$2/$3/$4/$5 permanent;
See this document for details.
If /images/i/P/2/L/iP2LROSEafC01584630756.jpg exists in server, it's served, if not then query is redirected to php file /make_image.php
This is achieved using a try_files statement within a location block that processes requests for URIs beginning with /images/.
For example:
location /images/ {
try_files $uri /make_image.php;
}
See this document for details.