D
D
Dmitry2021-11-28 14:14:24
htaccess
Dmitry, 2021-11-28 14:14:24

Why does the rule in .htaccess not work?

Good afternoon.
Please tell me why the redirect to webp does not work if you do this:

RewriteEngine On
RewriteCond %{HTTP_ACCEPT} image/webp 
RewriteCond %{REQUEST_FILENAME} (.*)\.(jpg|png)$
RewriteCond %1\.webp -f
RewriteRule (.+)\.(jpg|png)$ $1.webp [T=image/webp,E=REQUEST_image]
Header append Vary Accept env=REDIRECT_accept
AddType image/webp .webp


But at the same time, if you create a folder at the root /test/ and put two pictures pic.jpg and pic.webp in it, create an .htaccess in it with the same content and a simple test.html, <img src="pic.jpg">then go to site.ru/test/ test.html everything will work, the webp image will be displayed in a browser with support. But for some reason it doesn't work like this on a live site, a jpg image is always displayed. The path to the image is this: https://site.ru/img/item/5/1-small.jpg

Tried with REQUEST_URI and DOCUMENT_ROOT, same thing...
RewriteCond %{REQUEST_URI} (.*)\.(jpg|png)$
RewriteCond %{DOCUMENT_ROOT}%1\.webp -f


Thanks in advance!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question