Follow Brian Li (@DecryptoBL) on Twitter.
Follow Brian Li (@bwhli) on Instagram.

Redirect 7xx px wide images to full-size images in WordPress with NGINX

December 30, 2018

Recently. I noticed a bunch of 404 errors involving 700px and 768px wide images. These were “large” image sizes I used in previous WordPress themes. After doing a regex search and replace on my database to get rid of all instances of -7\d{2}x\d{3}, I added the following NGINX rule to redirect any potential external direct links to the images.

location ~* "^\/wp-content\/uploads\/(.*)(-7\d{2}x\d{3})(..{3})$"  {
   return 301$1$3;


Find me on Twitter, or send me an email.