Redirect to HTTP non-www to HTTPS www htaccess

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

    Try this methode:

    # Redirect 301 all to https://www
    
       RewriteCond %{HTTPS} off [OR]
       RewriteCond %{HTTP_HOST} !^www\. [NC]
       RewriteCond %{HTTP_HOST} ^(.*)$  [NC]
       RewriteRule (.*) https://www.example.com/$1 [L,R=301]
    
    

    Why sometimes you don't need code %{HTTP_HOST} and use your domain exact url with www for the last line, because usually the result will have two www like:

    https://www.www.yourdomain.com
    

    Btw if you use cloudflare, just create pagerules redirect 301 all to https and www version.

    Create pagerules Fill with

    example.com/*
    

    Choose setting forward url then choose 301 and fill with this

    https://www.example.com/$1
    

    Save it and all will be redirected to https and www version.

提交回复
热议问题