#### BEGIN atec-webp
# DO NOT EDIT THESE LINES
# Serve .webp with correct MIME type
AddType image/webp .webp
# Ensure caches respect image type negotiation
Header set Vary "Accept-Encoding"
Header unset Vary env=dont-vary
Header set Vary "Accept" "expr=%{REQUEST_URI} =~ m#\.(webp|jpe?g|png|gif|bmp)$#"
RewriteEngine On
# Only continue if browser supports WebP
RewriteCond %{HTTP_ACCEPT} image/webp
# Skip if request is already .webp
RewriteCond %{REQUEST_URI} !\.webp$ [NC]
# 1. Serve .Xwebp.webp if exists (e.g., for quality variants)
RewriteCond %{REQUEST_FILENAME}.Xwebp.webp -f
RewriteRule ^(.+)$ $1.Xwebp.webp [T=image/webp,E=no-gzip:1,E=no-brotli:1,E=dont-vary:1,L]
# 2. Serve plain .webp if exists
RewriteCond %{REQUEST_FILENAME}.webp -f
RewriteRule ^(.+)$ $1.webp [T=image/webp,E=no-gzip:1,E=no-brotli:1,E=dont-vary:1,L]
# 3. Fallback to dynamic conversion via local img2webp
RewriteRule ^(.+\.(jpe?g|png|gif|bmp))$ atec-webp/img2webp.php?src=$1 [QSA,E=no-gzip:1,E=no-brotli:1,E=dont-vary:1,L]
#### END atec-webp