Skip to content

Instantly share code, notes, and snippets.

@pongo
Last active March 5, 2020 07:49
Show Gist options
  • Save pongo/268228500b6270d368202902478203e5 to your computer and use it in GitHub Desktop.
Save pongo/268228500b6270d368202902478203e5 to your computer and use it in GitHub Desktop.
serves a .webp image instead of jpg/png
<IfModule mod_rewrite.c>
RewriteEngine On
# serves a .webp image instead of jpg/png
RewriteCond %{HTTP_ACCEPT} image/webp
RewriteCond %{REQUEST_FILENAME} ^(.+)\.(jpe?g|png)$
RewriteCond %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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment