htaccess force https and redirect www to non-www, but no other subdomains

后端 未结 6 738
醉话见心
醉话见心 2020-12-01 11:03

I know there are many similar threads, but none of them seems to match my exact problem. Here is what I’m trying to do:

(1) http://www.mydomain.com/ -> ht         


        
6条回答
  •  猫巷女王i
    2020-12-01 11:23

    Put this code in your DOCUMENT_ROOT/.htaccess file:

    RewriteEngine On
    
    RewriteCond %{HTTPS} off
    RewriteCond %{ENV:HTTPS} off
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
    
    RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
    RewriteRule ^ https://%1%{REQUEST_URI} [L,R=301,NE]
    

提交回复
热议问题