.htaccess - 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 图像),但它只是不断返回自身
解决方案
推荐阅读
- php - 在 PHP 中的页面刷新时生成新令牌
- jestjs - 尝试访问 mockedFunction.mock.instaces 属性在 Jest 中给出 undefined
- java - MockMultipartFile 在实际环境中不起作用,因为它在 spring 的测试包中可用。有什么解决方法吗?
- c++ - 获取列表迭代器索引
- ios - iOS DOM 树不代表屏幕上的对象
- javascript - 为什么我的 for/in 循环给我空结果,但我的常规 for 循环没有(图片)?
- java - 启用工具栏图标时如何显示汉堡图标
- javascript - 如何在 javascript 或 MySQL 中对数据透视动态数组进行分组?
- sails.js - SailsJS 中的全局模型无法访问
- c++ - 如何使用 unique_ptr 进行迭代?