Serve a same-folder WebP alternative with Apache
This example serves image.jpg.webp for a request to image.jpg when the browser accepts WebP. It is an optional Apache integration, not a rule generated by the POM Cache interface.
Test it on staging and adapt it to the actual image generator and document root.
Prepare a real pair
Choose one non-critical upload and confirm both files are valid:
wp-content/uploads/2026/07/example.jpg
wp-content/uploads/2026/07/example.jpg.webp
Open each file directly before adding negotiation. The WebP file must already be generated; Apache does not convert the JPEG during the request.
Example Apache block
Place the reviewed block before WordPress’s existing-file/front-controller rules:
# BEGIN same-folder WebP
<IfModule mod_mime.c>
AddType image/webp .webp
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_ACCEPT} image/webp [NC]
RewriteCond %{REQUEST_FILENAME} \.(?:jpe?g|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_FILENAME}.webp -f
RewriteRule ^(.+\.(?:jpe?g|png))$ $1.webp [NC,L]
</IfModule>
<IfModule mod_headers.c>
<FilesMatch "\.(?:jpe?g|png|webp)$">
Header merge Vary Accept
</FilesMatch>
</IfModule>
# END same-folder WebP
The block uses:
mod_rewriteto select the alternative;mod_mimeto associate.webpwithimage/webp;mod_headersto mergeAcceptintoVary.
Apache documents extension-to-media-type mapping in mod_mime and conditional header changes in mod_headers.
Understand each condition
HTTP_ACCEPT prevents WebP delivery to a client that did not request it.
The filename condition limits negotiation to JPEG and PNG requests. The two -f checks require both the original and original.webp files to exist.
The internal rewrite keeps the viewer URL unchanged:
viewer URL: /uploads/example.jpg
served file: /uploads/example.jpg.webp
Header merge avoids adding a duplicate Accept token when another rule already supplied it.
If your generator uses image.webp
Do not use the example unchanged. The existence check and substitution must remove the original extension rather than append .webp.
Write down sample pairs for .jpg, .jpeg, and .png, including uppercase filenames if the filesystem is case-sensitive, and have the server administrator validate the resulting expression.
One rule must not sometimes expect image.jpg.webp and sometimes image.webp.
Validate at the origin
Bypass the CDN, then make two requests to the original public URL.
With WebP support:
curl -sS -D - -o /dev/null \
-H 'Accept: image/webp,image/*,*/*' \
'https://example.com/wp-content/uploads/2026/07/example.jpg'
Without WebP support:
curl -sS -D - -o /dev/null \
-H 'Accept: image/jpeg,image/*,*/*' \
'https://example.com/wp-content/uploads/2026/07/example.jpg'
The first response should be Content-Type: image/webp; the second should remain image/jpeg. Both should include an appropriate Vary value containing Accept.
Also compare the response bytes or browser image information. Headers alone cannot prove that the body uses the claimed format.
Add the CDN last
Configure the CDN so the original public URL has distinct cache variants for compatible and incompatible Accept values. Purge any image object cached before this policy was enabled.
Then repeat both requests through the public distribution. If both receive whichever format was requested first, the edge cache key is incomplete.
Use Keep the original image as a safe fallback before applying the rule to the full uploads tree.