Wordpress Htaccess将模块库图像文件名重新写入LiteSpeed缓存图像
我正在使用WordPress的Modula Pro图像库插件,加载的所有缩略图都具有以下URL格式之一:Wordpress Htaccess将模块库图像文件名重新写入LiteSpeed缓存图像,wordpress,.htaccess,url-rewriting,litespeed,Wordpress,.htaccess,Url Rewriting,Litespeed,我正在使用WordPress的Modula Pro图像库插件,加载的所有缩略图都具有以下URL格式之一: 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 https://example.com/wp-content/uploads/s
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
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
我还使用LiteSpeed缓存,它使用以下URL格式生成相同的图像,大小约为原来的3-4倍:
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
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
我已尝试将此添加到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>
重新启动发动机
重写基/
重写规则^(+)-99999x300.jpg$1-169x300.jpg[QSA,L]
重写规则^(+)-300x99999.jpg$1-300x169.jpg[QSA,L]
我做错了什么?以下是有效的方法。因为我使用的是OpenLiteSpeed服务器,所以我需要后面的斜杠才能工作:
RewriteRule /(.+)-300x99999.jpg /$1-300x169.jpg [QSA,L]
RewriteRule /(.+)-99999x300.jpg /$1-169x300.jpg [QSA,L]
由于Modula Gallery创建了自己的缩略图,LiteSpeed缓存的图像要小得多,因此我的目标是提供优化的图像。事实证明,根据图片的原始大小,我需要的URL是300x169或300x225。最后,我检查以确保在每个规则之前存在重写条件的文件:
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]
以下是有效的方法。因为我使用的是OpenLiteSpeed服务器,所以我需要后面的斜杠才能工作:
RewriteRule /(.+)-300x99999.jpg /$1-300x169.jpg [QSA,L]
RewriteRule /(.+)-99999x300.jpg /$1-169x300.jpg [QSA,L]
由于Modula Gallery创建了自己的缩略图,LiteSpeed缓存的图像要小得多,因此我的目标是提供优化的图像。事实证明,根据图片的原始大小,我需要的URL是300x169或300x225。最后,我检查以确保在每个规则之前存在重写条件的文件:
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]
是否要将“xxx-9999x300.jpg”重写为“xxx-169x300.jpg”?你在使用LiteSpeed Web服务器吗?是的,这就是我要重写的。我使用的是OpenLiteSpeed Web服务器,您想将“xxx-9999x300.jpg”重写为“xxx-169x300.jpg”吗?你在使用LiteSpeed Web服务器吗?是的,这就是我要重写的。我正在使用OpenLiteSpeed Web服务器