1

I'm using the Modula Pro image gallery plugin for WordPress and all of the thumbnail images that load have either of these URL formats:

https://example.com/wp-content/uploads/sites/3/2020/08/filename-300x99999.jpg
https://example.com/wp-content/uploads/sites/3/2020/08/filename-99999x300.jpg

I'm also using LiteSpeed Cache and it's producing the same image about 3-4 times smaller in size with the following URL formats:

https://example.com/wp-content/uploads/sites/3/2020/08/filename-300x168.jpg
https://example.com/wp-content/uploads/sites/3/2020/08/filename-168x300.jpg

I've tried adding this to htaccess:

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  RewriteRule ^(.+)-99999x300.jpg $1-169x300.jpg [QSA,L]
  RewriteRule ^(.+)-300x99999.jpg $1-300x169.jpg [QSA,L]
</IfModule>

What am I doing wrong?

Roy Handy
  • 11
  • 2

1 Answers1

0

The following is what worked. Since I was using an OpenLiteSpeed server, I needed the trailing slashes for it to work:

RewriteRule /(.+)-300x99999.jpg /$1-300x169.jpg [QSA,L]
RewriteRule /(.+)-99999x300.jpg /$1-169x300.jpg [QSA,L]

Since Modula Gallery created its own thumbnails and the images that LiteSpeed Cache were much smaller, my goal was to serve the optimized images instead. It turns out, that depending on the original size of the images, the URL I needed was going to be either 300 x 169 or 300 x 225. I ended up checking to make sure the files existed with a rewrite condition before each rule:

RewriteCond %{REQUEST_URI} ^/(.+)-300x99999.jpg$
RewriteCond %{DOCUMENT_ROOT}/$1-300x169.jpg -f [NC]
RewriteRule /(.+)-300x99999.jpg /$1-300x169.jpg [QSA,L]

RewriteCond %{REQUEST_URI} ^/(.+)-300x99999.jpg$
RewriteCond %{DOCUMENT_ROOT}/$1-300x225.jpg -f [NC]
RewriteRule /(.+)-300x99999.jpg /$1-300x225.jpg [QSA,L]

RewriteCond %{REQUEST_URI} ^/(.+)-99999x300.jpg$
RewriteCond %{DOCUMENT_ROOT}/$1-169x300.jpg -f [NC]
RewriteRule /(.+)-99999x300.jpg /$1-169x300.jpg [QSA,L]

RewriteCond %{REQUEST_URI} ^/(.+)-99999x300.jpg$
RewriteCond %{DOCUMENT_ROOT}/$1-225x300.jpg -f [NC]
RewriteRule /(.+)-99999x300.jpg /$1-225x300.jpg [QSA,L]
Roy Handy
  • 11
  • 2