In nginx config, what is the best way to return the original image when the required image size was not found given wordpress image naming/size notation conventions.
So, say if /image-name-150x170.png not found, I want /image-name.png to be returned. -150-170 part can be some other numbers. Therefore, I want dash 1-4 digits x 1-4 digits before dot in the file name to be removed.
I want to put the replace in uri code inside @static_full location block or rewrite. wondering which would be better performance-wise.
#some locations here and then location ~* ^.+\.(png|gif|jpg|jpeg){ access_log off; log_not_found off; expires max; error_page 404 = @static_full; #if not found, seek #static_ful } location @static_full{ #modify uri here to remove image dimensions like below #uri = remove dash 1-4 digits x 1-4 digits before dot #or rewrite to original name } location / { try_files $uri $uri/ /index.php?$args ; } UPDATE, I figured out how to do it. The following did what I wanted to do.
location @static_full{ #modify uri here to remove image dimensions like below #uri = remove dash three digits x three digits before dot rewrite "^(.*)(-[\d]{1,4}+x[\d]{1,4}+.)([\w]{3,4})" $1.$3 break; }
try_filesin thelocation? Or do you actually want the return code to be a 404?