Correct Nginx Rule to Server WebP Images
-
I am trying to server webp images to supporting browsers by using the code below. I have already .webp images in addition to .png and .jpg images of the same file.
For example if have an image named vacation.jpg, i also have vacation.jpg.webp.
The code below serves users with supporting browsers WEBP images but when i look at the URL i see it is named as vacation.jpg.webp
But i want its named written in URL as vacation.webp
How can i modify it to do it?
[ Moderator note: code fixed. Please wrap code in the backtick character or use the code button. ]
location ~ ^(/wp-content.+)\.(jpe?g|png)$ { set $red Z; if ($http_accept ~* "webp") { set $red A; } if (-f $request_filename.webp) { set $red "${red}B"; } if ($red = "AB") { add_header Vary Accept; rewrite (.*) $1.webp redirect; } }
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Correct Nginx Rule to Server WebP Images’ is closed to new replies.