Force SSL HTTPS for subdomain with .htaccess

前端 未结 2 1549
南方客
南方客 2021-01-13 07:21

I have this code for forcing SSL on a website generally:

RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-13 08:23

    For debugging I use a website I found http://martinmelin.se/rewrite-rule-tester/

    Using the rules you provided

    RewriteCond %{HTTPS} !=on
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    

    I got an error at

    RewriteCond %{HTTPS} !=on
    

    This might work for you

    RewriteCond %{HTTPS} off
    RewriteRule (.*) https://%{SERVER_NAME}/%$1 [R,L] 
    

    Found the above example at https://www.sslshopper.com/apache-redirect-http-to-https.html

提交回复
热议问题