Redirect to HTTP non-www to HTTPS www htaccess

前端 未结 12 1094
醉话见心
醉话见心 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:45

    This is http to https and non www to www redirection using .htaccess

    If you want to redirect to https and www you can use this code

    http to https redirection:

    
    RewriteEngine On
    RewriteCond %{HTTPS} !on
    RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
    
    

    Non www to www redirection:

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

    If you want to use booth functionality place the above all code respectively

提交回复
热议问题