Force HTTPS on certain URLs and force HTTP for all others

后端 未结 4 1652
孤独总比滥情好
孤独总比滥情好 2020-12-03 03:15

I have a client project where I need to force HTTPS for a certain folder and force HTTP for all others. I can sucessfully enforce HTTPS for the folder I desire but then all

4条回答
  •  [愿得一人]
    2020-12-03 03:53

    This is something that works from an old client website and could be adaptable for your purposes:

    #If https off and in the cart dir
    RewriteCond %{HTTPS} =off [NC]
    RewriteCond %{REQUEST_URI} ^/cart/(.*) [NC]
    RewriteRule ^(.*)$ https://%{HTTP_HOST}/cart/%1 [R=301,L]
    
    #If https on and not in cart dir    
    RewriteCond %{HTTPS} =on
    RewriteCond %{REQUEST_URI} !^/cart [NC]
    #Above line actually used to read RewriteCond %{REQUEST_URI} !^/cart|media|images|thumbs|css|js [NC]
    #to allow js/css/images to be served so there were no mixed ssl messages popping up to visitors
    RewriteCond %{REQUEST_FILENAME} !index\.php$ [NC]
    RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [R=301,L]
    
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
    

    Replacing cart with my perhaps

提交回复
热议问题