Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6057891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:32:17+00:00 2026-05-23T08:32:17+00:00

Is it possible to use mod_negotiation to serve up a webp image if the

  • 0

Is it possible to use mod_negotiation to serve up a webp image if the browser supports it, and a jpg otherwise?

For instance, if I link to an image with the path /images/test, it serves the image found at /images/test.webp if the UA knows about webp, or jpg otherwise?

I’ve tried poking around, but it seems that the Accept headers in Chrome at least look like Accept:*/*, rather than specifying the image type.

If this isn’t the way to do it, has anyone got any other suggestions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T08:32:18+00:00Added an answer on May 23, 2026 at 8:32 am

    For serving WebP images, I use a rewrite rule in nginx that checks for the existence of the file and support for WebP images. I ported it over to Apache mod_rewrite since the OP mentioned mod_negotiation. The rewrite looks for a User Agent containing the word “chrome” and than checks for a file with a .webp extension with the same name and path as the .jpg or the .png file and if so serves the WebP file. The rewrite rule is a bit kludgy but it gets the job done.

    AddType image/webp .webp
    # strip the extension off of all JPGs
    RewriteCond %{HTTP_USER_AGENT} (chrome) [NC]
    RewriteRule (.*)\.jpg$ $1
    
    #check for a webp file, if so serve it
    RewriteCond   %{REQUEST_FILENAME}.webp  -f
    RewriteRule   (.*)  $1.webp [E=WEBP:1]
    
    #check for if we did not have a webp file and we do have a jpg, if so serve it
    RewriteCond   %{REQUEST_FILENAME}.jpg  -f
    RewriteCond   %{REQUEST_FILENAME}.webp  !-f
    RewriteRule   (.*)  $1.jpg
    
    # strip the extension off of all PNGs
    RewriteCond %{HTTP_USER_AGENT} (chrome) [NC]
    RewriteRule (.*)\.png$ $1
    
    #check for a webp file, if so serve it
    RewriteCond   %{REQUEST_FILENAME}.webp  -f
    RewriteRule   (.*)  $1.webp [E=WEBP:1]
    
    #check for if we did not have a webp file and we do have a png, if so serve it
    RewriteCond   %{REQUEST_FILENAME}.png  -f
    RewriteCond   %{REQUEST_FILENAME}.webp  !-f
    RewriteRule   (.*)  $1.png
    

    For my site, I have the luxury of being able to load my photos in via JavaScript after I can detect the support for WebP in the browser instead of relying on the user agent string. If WebP support exists than I set a cookie before I begin loading in my images. Therefore instead of this RewriteCond

    RewriteCond %{HTTP_USER_AGENT} (chrome) [NC]
    

    I would use this

    RewriteCond %{HTTP_COOKIE} supports_webp
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to use a flash document embedded in HTML as a link?
Is it possible use mod_rewrite to resolve addresses hosted on another server? Say I
I have recently started looking into Google Charts API for possible use within the
Possible Duplicate: Use SVN Revision to label build in CCNET I'm working through the
Is possible to use ArcSDE API in .NET(C#) ? http://edndoc.esri.com/arcsde/9.2/api/capi/dbconnects/dbconnects.htm Thanks
Is it possible to use Apache Subversion (SVN) as general purpose backup tool? (As
Is it possible to use Microsoft Entity Framework with Oracle database?
Is it possible to use an UnhandledException Handler in a Windows Service? Normally I
Is it possible to use gcov for coverage testing of multi-threaded applications? I've set
Is it possible to use an IF clause within a WHERE clause in MS

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.