Created
July 1, 2022 11:59
-
-
Save JasperE84/0e864f947267456d0a460ee76ba5afa7 to your computer and use it in GitHub Desktop.
.htaccess webp redirection if exists and client accept header permits
This file contains hidden or 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 | |
RewriteBase / | |
# check if browser accepts webp | |
RewriteCond %{HTTP_ACCEPT} image/webp | |
# check if file is jpg or png | |
RewriteCond %{REQUEST_FILENAME} (.*\.(jpe?g|png))$ | |
# check if corresponding webp file exists image.png -> image.webp | |
RewriteCond %1\.webp -f | |
# serve up webp instead | |
RewriteRule (.+\.(jpe?g|png))$ $1.webp [T=image/webp,E=accept:1] | |
</IfModule> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment