Redirect non-www to www in .htaccess

后端 未结 13 1746
轻奢々
轻奢々 2020-11-22 05:51

I have this in my .htaccess file:

RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule (.*) http://www.example.com$1 [R=301,L]

but whenever I

13条回答
  •  广开言路
    2020-11-22 06:30

    Here's the correct solution which supports https and http:

    # Redirect to www
    RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
    RewriteCond %{HTTPS}s ^on(s)|
    RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    

提交回复
热议问题