Last active
October 9, 2024 00:33
-
-
Save sergejmueller/5500879 to your computer and use it in GitHub Desktop.
Apache: Detecting WebP support with Header Vary Accept
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<IfModule mod_rewrite.c> | |
RewriteEngine On | |
RewriteCond %{HTTP_ACCEPT} image/webp | |
RewriteCond %{DOCUMENT_ROOT}/$1.webp -f | |
RewriteRule (.+)\.(jpe?g|png)$ $1.webp [T=image/webp,E=accept:1] | |
</IfModule> | |
<IfModule mod_headers.c> | |
Header append Vary Accept env=REDIRECT_accept | |
</IfModule> | |
AddType image/webp .webp |
What exactly is this code supposed to do?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@MusikDK, you probably see a .png files because that's what the URL in the page points to. But the server is serving an webp image "disguised" as a file with extension .png. It's an internal rewrite.