Skip to content

Instantly share code, notes, and snippets.

@seansch
Last active December 31, 2021 02:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seansch/e407ff1a20741a8a72f59b51c85c7b9e to your computer and use it in GitHub Desktop.
Save seansch/e407ff1a20741a8a72f59b51c85c7b9e to your computer and use it in GitHub Desktop.
Apache detect browser support and serve webp images
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_ACCEPT} image/webp
RewriteCond %{REQUEST_URI} (?i)(.*)(\.jpe?g|\.png)$
RewriteCond %{DOCUMENT_ROOT}%1.webp -f
RewriteRule (?i)(.*)(\.jpe?g|\.png)$ %1\.webp [L,T=image/webp,R]
</IfModule>
<IfModule mod_headers.c>
Header append Vary Accept env=REDIRECT_accept
</IfModule>
AddType image/webp .webp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment