-
-
Save gravataLonga/181e7b2b22855d4c5a1bc2e032a89bc0 to your computer and use it in GitHub Desktop.
enabling apache to serve WebP image files if accepted by browser (and .webp files available)
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
# originally from https://groups.google.com/a/webmproject.org/group/webp-discuss/browse_thread/thread/196ac4ea705688d8 | |
<IfModule mod_rewrite.c> | |
# TODO: don't forget to put | |
# AddType image/webp .webp | |
# in your mods-available/mime.conf | |
# (though this is optional because we're setting | |
# the mime type manually in the RewriteRule) | |
# Enable rewrite | |
RewriteEngine On | |
# Does browser support WebP? | |
RewriteCond %{HTTP_ACCEPT} \bimage/webp\b | |
# Capture image name | |
RewriteCond %{REQUEST_URI} (.*)(\.(jpe?g|png))$ | |
# if you don't have all jpg/png images available | |
# as webp then you want to uncomment the next line | |
# so apache first checks if there is a webp file | |
# otherwise leave it disabled as it removes the | |
# need to query the disk | |
#RewriteCond %{DOCUMENT_ROOT}%1.webp -f | |
# Route to WebP image | |
RewriteRule .* %1\.webp [L,T=image/webp] | |
</IfModule> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment