• You MUST read the Babiato Rules before making your first post otherwise you may get permanent warning points or a permanent Ban.

    Our resources on Babiato Forum are CLEAN and SAFE. So you can use them for development and testing purposes. If your are on Windows and have an antivirus that alerts you about a possible infection: Know it's a false positive because all scripts are double checked by our experts. We advise you to add Babiato to trusted sites/sources or disable your antivirus momentarily while downloading a resource. "Enjoy your presence on Babiato"

Can someone help me with .htaccess file

thambyz

Active member
Babiato Lover
Mar 18, 2021
124
64
28
Hi,
I have a folder /assets/admin/images/products which contains .jpg and .png files and another folder /assets/admin/images/products/webp with the webp version of .jpg and .png files with name filename.webp (jpg and png is not added in file names)

How do i serve webp version in supported browsers using htaccess

I found some information at https://github.com/vincentorback/WebP-images-with-htaccess but it only serves from same folder.

Thanks
 
Hi I can help you with this
Thank you. This code is working if webp image is in same folder. I need to modify it to look in another folder.

Code:
  RewriteCond %{DOCUMENT_ROOT}/$1.webp -f
  RewriteRule (.+)\.(jpe?g|png|gif)$ $1.webp [T=image/webp,E=REQUEST_image]
 
Thank you. This code is working if webp image is in same folder. I need to modify it to look in another folder.

Code:
  RewriteCond %{DOCUMENT_ROOT}/$1.webp -f
  RewriteRule (.+)\.(jpe?g|png|gif)$ $1.webp [T=image/webp,E=REQUEST_image]
what's the dir or name of the folder?
 
  • Like
Reactions: thambyz
what's the dir or name of the folder?
This is the folder with jpg,jpeg and png images (ex: image.png)
/assets/admin/images/products


This is the folder with webp version(eg: image.webp)
/assets/admin/images/products/webp
 
The solution is already in the GitHub link that you posted.

replace the "path to image" with the actual path to the file/folder of your resources.


1667692650423.png

You can check these info too:

 
  • Like
Reactions: thambyz
The solution is already in the GitHub link that you posted.

replace the "path to image" with the actual path to the file/folder of your resources.

Thanks for the update. But the issue is it is not possible to edit the actual code. The code is in PHP with codeigniter framework which i don't have idea and i don't want to touch the actual code, that is the reason i am looking for htaccess option. And this is also the reason i don't want to put optimized webp images in actual folder so i can easily revert the changes done. But i think this is the easiest way to put webp images inside images folder and later delete webp images later if required.
 
Below code is working.


Code:
<IfModule mod_rewrite.c>
  RewriteEngine On
    # Check if browser supports WebP images
  RewriteCond %{HTTP_ACCEPT} image/webp

  # Check if WebP replacement image exists
  RewriteCond %{DOCUMENT_ROOT}/assets/admin/images/products/webp/$1.webp -f

  # Serve WebP image instead
  RewriteRule (.+)\.(jpe?g|png|gif)$ webp/$1.webp [T=image/webp,E=REQUEST_image]
</IfModule>

<IfModule mod_headers.c>
  # Vary: Accept for all the requests to jpeg, png and gif
  Header append Vary Accept env=REQUEST_image
</IfModule>

<IfModule mod_mime.c>
  AddType image/webp .webp
</IfModule>
 
AdBlock Detected

We get it, advertisements are annoying!

However in order to keep our huge array of resources free of charge we need to generate income from ads so to use the site you will need to turn off your adblocker.

If you'd like to have an ad free experience you can become a Babiato Lover by donating as little as $5 per month. Click on the Donate menu tab for more info.

I've Disabled AdBlock