How to redirect from www to https www with htacces?

后端 未结 4 1783
北恋
北恋 2021-01-21 15:42

I need to do the following: My current address looks like: https://www.domain.com

I want to redirect with htaccess: www.domain.com TO https://www.domain.com and http:/

4条回答
  •  南方客
    南方客 (楼主)
    2021-01-21 16:20

    The best way is:

    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    

    With using %{HTTP_HOST} you don't need to write domain name

提交回复
热议问题