首页 > 解决方案 > Htaccess 不会将 jpg/png 图像重定向到脚本以在旅途中进行 webp 转换

问题描述

htacces 中的代码适用于除图像之外的所有内容(唯一需要重定向的内容)。使用 Cloudways 和 Prestashop。它与 Mamp 一起在本地工作

我已经尝试让它重定向 averything(删除条件)并且它使所有东西都重定向(使它成为一个 php 错误,因为它不是一个图像)但图像仍然没有被重定向。

# Redirect images to webp-on-demand.php (if browser supports webp)
RewriteCond %{HTTP_ACCEPT} image/webp
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.*)\.(jpe?g|png)$ webp-on-demand.php?source=%{SCRIPT_FILENAME} [NC,L]

我试过了

# Redirect images to webp-on-demand.php (if browser supports webp)
RewriteCond %{HTTP_ACCEPT} image/webp
RewriteCond %{REQUEST_FILENAME} 
RewriteRule webp-on-demand.php?source=%{SCRIPT_FILENAME} [NC,L]

这会导致除图像之外的所有内容都出错(它们返回自身而不是压缩结果)

http://dev-cz.mamalabels.com/webp-on-demand.php?source=img/att/183/222-cs.png 带有脚本的 网址 https://dev-cz.mamalabels.com/img/ att/183/222-cs.png 图片的网址

图像应该返回一个页面,其中脚本说明它是如何被压缩的(稍后返回一个 webp 图像),但它只是不断返回自身

标签: .htaccessprestashopwebpcloudways

解决方案


推荐阅读