Redirect to HTTP non-www to HTTPS www htaccess

前端 未结 12 1093
醉话见心
醉话见心 2020-12-01 08:05

I want to redirect from any direction to our site with HTTPS protocol, but some redirects it\'s not working. I want this:

  • http://www.site.co TO
12条回答
  •  情深已故
    2020-12-01 08:50

    Try it like this:

    RewriteEngine On
    
    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
    
    RewriteCond %{HTTPS} off
    RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301] 
    

    The only real difference here is that first we redirect from non-WWW to WWW then we check for HTTPS and redirect it.

    If it does not work, try this one:

    RewriteEngine On
    
    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
    
    RewriteCond %{SERVER_PORT} !^443$
    RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301] 
    

提交回复
热议问题