Answer the question
In order to leave comments, you need to log in
How to set an expression only for the main page?
I'm preloading an image for the main page. I wrote the code, but the preload works on any url. How do I restrict it to the main one only?
Or, is it possible to set the variable in some other way only on the main page?
# Добавляем предзагрузку файла
# Если мы на главной странице, и есть кука res_pushed со значением true, устанавливаем флаг RES_PUSHED в любое значение - главное чтобы он был
# Далее будем проверять флаг: если он отсутствует - добавляем заголовок Link и устанавливаем куку res_pushed
RewriteCond %{REQUEST_URI} ^/index.php$ [OR]
RewriteCond %{REQUEST_URI} ^/$
RewriteCond %{HTTP_COOKIE} ^.*res_pushed=true.*$ [NC]
RewriteRule .* - [E=RES_PUSHED:anyValue]
Header add Link "</lcp.webp>;rel=preload;as=image" env=!RES_PUSHED
Header add Set-Cookie "res_pushed=true; Max-Age=1200; Path=/" env=!RES_PUSHED
Answer the question
In order to leave comments, you need to log in
Header add Link "</lcp.webp>;rel=preload;as=image" env=!RES_PUSHED
Header add Set-Cookie "res_pushed=true; Max-Age=1200; Path=/" env=!RES_PUSHED
SetEnvIf Request_URI "^(?!/$|/index\.php$)" RES_PUSHED=1
env=!
and(?!...)
Header add Link "</lcp.webp>;rel=preload;as=image" env=RES_PUSHED
Header add Set-Cookie "res_pushed=true; Max-Age=1200; Path=/" env=RES_PUSHED
SetEnvIf Request_URI "^(/|/index\.php)$" RES_PUSHED=1
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question