且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用htaccess提供webp图像?

更新时间:2023-11-29 15:52:16

如果请求的URL以jpegpng结尾,则可以使用

If the requested URL ends in jpeg or png, you might test for the corresponding webp with

RewriteCond %{REQUEST_FILENAME}.webp -f
RewriteRule ^ %{REQUEST_FILENAME}.webp [L]

如果愿意的话,您可能会有更多的限制

You may be more restrictive, if you like

RewriteCond %{REQUEST_FILENAME}.webp -f
RewriteRule \.(jpe?g|png)$ %{REQUEST_FILENAME}.webp [L]

如果条件和规则不匹配,请求将失败并按原样提供文件(.jpg/.png).

If the condition and rule don't match, the request will fall through and serve the file (.jpg/.png) as is.