Correctly switching between HTTP and HTTPS using .htaccess

后端 未结 6 1782
挽巷
挽巷 2020-11-28 08:14

We\'ve got a shopping site which we\'re hosting on a shared host (Mediatemple Gridserver). Some parts of the site need to use HTTPS (checkout etc) but the rest should be usi

6条回答
  •  春和景丽
    2020-11-28 09:00

    I use something similar to this for my admin folder in wordpress:

    #redirect all https traffic to http, unless it is pointed at /checkout
    RewriteCond %{HTTPS} on
    RewriteCond %{REQUEST_URI} !^/checkout/?.*$
    RewriteRule ^(.*)$ http://mydomain.com/$1 [R=301,L]
    

    The RewriteCond %{HTTPS} on portion may not work for all web servers. My webhost requires RewriteCond %{HTTP:X-Forwarded-SSL} on, for instance.

    If you want to force the reverse, try:

    #redirect all http traffic to https, if it is pointed at /checkout
    RewriteCond %{HTTPS} off
    RewriteCond %{REQUEST_URI} ^/checkout/?.*$
    RewriteRule ^(.*)$ https://mydomain.com/$1 [R=301,L]
    

    If you want some alternate ways to do it, check out askapache.

提交回复
热议问题