How to correctly formulate the check in htaccess? I need to make a redirect on https with http not for the entire site but only for 2 folders when you are in the same folder for the same file, also do not redirect

for example

https:

http://site.com/test1/

http://site.com/test2/

but not for http://site.com/test2/some.php

everything else http

    1 answer 1

    RewriteEngine on # если порт отличен от 443 RewriteCond %{SERVER_PORT} !^443$ # другое определение не https #RewriteCond %{HTTPS} !=on # и если идет обращение к папке test1 или test2 RewriteCond %{REQUEST_URI} ^/(test1|test2)/ # и если это не /test2/some.php RewriteCond %{REQUEST_URI} !^/test2/some.php # то перейти на https RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [QSA,R=301,L] 

    UPD Rather like this:

     # если порт равен 443 RewriteCond %{SERVER_PORT} ^443$ # другое определение https #RewriteCond %{HTTPS} =on # и если не идет обращение к папке test1 или test2 RewriteCond %{REQUEST_URI} !^/(test1|test2)/ [OR] # или если это /test2/some.php RewriteCond %{REQUEST_URI} ^/test2/some.php # то перейти на http RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [QSA,R=301,L] 
    • and it is possible to create something else for checking ru.stackoverflow.com/questions/707916/… - vov4ok
    • one
      @ vov4ok, write the second block of conditions that are opposite to the first and at the end of the RewriteRule to the second link. - Visman
    • something like this? RewriteEngine on RewriteCond% {SERVER_PORT} ^ 443 $ RewriteCond% {REQUEST_URI}! ^ / (Test1 | test2) / RewriteCond% {REQUEST_URI} ^ / test2 / some.php RewriteRule ^ (. *) $ Http: //% {HTTP_HOST } / $ 1 [QSA, R = 301, L] - vov4ok
    • one
      @ vov4ok, added in response. - Visman
    • thanks a lot - vov4ok