Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

webp image is created but not served #5

Open
nafribs opened this issue Feb 29, 2024 · 1 comment
Open

webp image is created but not served #5

nafribs opened this issue Feb 29, 2024 · 1 comment

Comments

@nafribs
Copy link

nafribs commented Feb 29, 2024

I installed the module and checked the image is being created.

image

But no webp image is being served.

Below is what was added to htaccess by the module.

~~ mdn_webp_start

RewriteEngine On

Check if browser supports WebP images

RewriteCond %{HTTP_ACCEPT} image/webp

Check if WebP replacement image exists

RewriteCond %{DOCUMENT_ROOT}/$1.webp -f

Serve WebP image instead

RewriteRule (.+).(jpe?g|png|gif)$ $1.webp [T=image/webp,E=REQUEST_image]

Vary: Accept for all the requests to jpeg, png and gif

Header append Vary Accept env=REQUEST_image

AddType image/webp .webp # ~~ mdn_webp_end
@hjelmua
Copy link

hjelmua commented Jan 14, 2025

For me the following rules worked:

  1. I rewrote the RewriteRules to serve both. I added the conditions after the rule.

Images

RewriteCond %{HTTP_HOST} ^domain.name.com$
RewriteRule ^(([\d])(?:-[\w-])?)/.+(.(?:jpe?g|webp|png|avif))$ %{ENV:REWRITEBASE}img/p/$2/$1$3 [L]
RewriteCond %{HTTP_HOST} ^domain.name.com$
RewriteRule ^(([\d])([\d])(?:-[\w-]
)?)/.+(.(?:jpe?g|webp|png|avif))$ %{ENV:REWRITEBASE}img/p/$2/$3/$1$4 [L]
RewriteCond %{HTTP_HOST} ^domain.name.com$
RewriteRule ^(([\d])([\d])([\d])(?:-[\w-])?)/.+(.(?:jpe?g|webp|png|avif))$ %{ENV:REWRITEBASE}img/p/$2/$3/$4/$1$5 [L]
RewriteCond %{HTTP_HOST} ^domain.name.com$
RewriteRule ^(([\d])([\d])([\d])([\d])(?:-[\w-]
)?)/.+(.(?:jpe?g|webp|png|avif))$ %{ENV:REWRITEBASE}img/p/$2/$3/$4/$5/$1$6 [L]
RewriteCond %{HTTP_HOST} ^domain.name.com$
RewriteRule ^(([\d])([\d])([\d])([\d])([\d])(?:-[\w-])?)/.+(.(?:jpe?g|webp|png|avif))$ %{ENV:REWRITEBASE}img/p/$2/$3/$4/$5/$6/$1$7 [L]
RewriteCond %{HTTP_HOST} ^domain.name.com$
RewriteRule ^(([\d])([\d])([\d])([\d])([\d])([\d])(?:-[\w-]
)?)/.+(.(?:jpe?g|webp|png|avif))$ %{ENV:REWRITEBASE}img/p/$2/$3/$4/$5/$6/$7/$1$8 [L]
RewriteCond %{HTTP_HOST} ^domain.name.com$
RewriteRule ^(([\d])([\d])([\d])([\d])([\d])([\d])([\d])(?:-[\w-])?)/.+(.(?:jpe?g|webp|png|avif))$ %{ENV:REWRITEBASE}img/p/$2/$3/$4/$5/$6/$7/$8/$1$9 [L]
RewriteCond %{HTTP_HOST} ^domain.name.com$
RewriteRule ^c/([\d]+)(-[.
\w-]*)/.+(.(?:jpe?g|webp|png|avif))$ %{ENV:REWRITEBASE}img/c/$1$2$3 [L]
RewriteCond %{HTTP_HOST} ^domain.name.com$
RewriteRule ^c/([a-zA-Z_-]+)(-[\d]+)?/.+(.(?:jpe?g|webp|png|avif))$ %{ENV:REWRITEBASE}img/c/$1$2$3 [L]

Check if browser supports WebP images

RewriteCond %{HTTP_ACCEPT} image/webp

Check if WebP replacement image exists

RewriteCond %{DOCUMENT_ROOT}/$1.webp -f

Serve WebP image instead

RewriteRule (.+).(jpe?g|png|gif)$ $1.webp [T=image/webp,E=REQUEST_image]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants