Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
added further info, clarified
Source Link
Selay
  • 101
  • 1
  • 4

I wantIn 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 three1-4 digits x three1-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.

Is it possible? Probably, or rewrite can also work?. 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 three1-4 digits x three1-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]+x[\d]+[\d]{1,4}+x[\d]{1,4}+.)(.*[\w]{3,4})" $1.$3 break; } 

I want to return the original image when the required image size was not found.

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 three digits x three digits before dot in the file name to be removed.

I want to put the replace in uri code inside @static_full location block.

Is it possible? Probably, rewrite can also work?

#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 three digits x three digits before dot } 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]+x[\d]+.)(.*) $1.$3 break; } 

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; } 
updated with the fix
Source Link
Selay
  • 101
  • 1
  • 4

I want to return the original image when the required image size was not found.

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 three digits x three digits before dot in the file name to be removed.

I want to put the replace in uri code inside @static_full location block.

Is it possible? Probably, rewrite can also work?

#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 three digits x three digits before dot } 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]+x[\d]+.)(.*) $1.$3 break; } 

I want to return the original image when the required image size was not found.

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 three digits x three digits before dot in the file name to be removed.

I want to put the replace in uri code inside @static_full location block.

Is it possible? Probably, rewrite can also work?

#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 three digits x three digits before dot } location / { try_files $uri $uri/ /index.php?$args ; } 

I want to return the original image when the required image size was not found.

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 three digits x three digits before dot in the file name to be removed.

I want to put the replace in uri code inside @static_full location block.

Is it possible? Probably, rewrite can also work?

#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 three digits x three digits before dot } 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]+x[\d]+.)(.*) $1.$3 break; } 
added 33 characters in body
Source Link
Selay
  • 101
  • 1
  • 4

I want to return the original image when the required image size was not found.

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 three digits x three digits before dot in the file name to be removed.

I want to put the replace in uri code inside @static_full location block.

Is it possible? Probably, rewrite can also work?

#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 three digits x three digits before dot } location / { try_files $uri $uri/ /index.php?$args ; } 

I want to return the original image when the required image size was not found.

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 three digits x three digits before dot in the file name to be removed.

I want to put the replace in uri code inside @static_full location block.

Is it possible?

#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 three digits x three digits before dot } location / { try_files $uri $uri/ /index.php?$args ; } 

I want to return the original image when the required image size was not found.

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 three digits x three digits before dot in the file name to be removed.

I want to put the replace in uri code inside @static_full location block.

Is it possible? Probably, rewrite can also work?

#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 three digits x three digits before dot } location / { try_files $uri $uri/ /index.php?$args ; } 
Source Link
Selay
  • 101
  • 1
  • 4
Loading