【问题标题】:Htaccess Re-Write Modula Gallery Image Filename to LiteSpeed Cached ImageHtaccess 将 Modula Gallery 图像文件名重写为 LiteSpeed 缓存图像
【发布时间】:2020-08-25 20:52:43
【问题描述】:

我正在使用适用于 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

我也在使用 LiteSpeed Cache,它使用以下 URL 格式生成相同的图像,大小大约小 3-4 倍:

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>

我做错了什么?

【问题讨论】:

  • 你想把“xxx-99999x300.jpg”改写成“xxx-169x300.jpg”吗?你在使用 LiteSpeed WebServer 吗?
  • 是的,这就是我要重写的内容。我正在使用 OpenLiteSpeed WebServer

标签: wordpress .htaccess url-rewriting litespeed


【解决方案1】:

以下是有效的。由于我使用的是 OpenLiteSpeed 服务器,因此我需要尾部斜杠才能使其工作:

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

由于 Modula Gallery 创建了自己的缩略图并且 LiteSpeed Cache 的图像要小得多,因此我的目标是提供优化的图像。事实证明,根据图像的原始大小,我需要的 URL 将是 300 x 169 或 300 x 225。我最终检查以确保文件在每个规则之前存在重写条件:

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]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-03-31
    • 1970-01-01
    • 1970-01-01
    • 2012-06-02
    • 1970-01-01
    • 1970-01-01
    • 2014-04-07
    • 1970-01-01
    相关资源
    最近更新 更多