[英]redirect all trafic to https://www.domain.com via htaccess
My ssl works on https://www.domain.com and not on https://domain.com
so I want to redirect https://domain.com to https://www.domain.com
我的ssl适用于https://www.domain.com而不是
https://domain.com
所以我想将https://domain.com重定向到https://www.domain.com
I used the solution I found here on how to edit htaccess to direct all traffic to a secure domain: 我使用了我在这里找到的关于如何编辑htaccess以将所有流量定向到安全域的解决方案:
#Http to https
#Exclude subdomains
RewriteCond %{HTTP_HOST} !^(sub1|sub2)
RewriteCond %{HTTP_HOST} ^(www\.)?domain.com$ [NC]
RewriteCond %{HTTPS} off
RewriteRule ^ https://www.domain.com%{REQUEST_URI} [NC,L,R]
#add www on ssl
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [NC,L,R]
However this does not work for the redirect of: 但是,这不适用于以下重定向:
https://domain.com
to https://www.domain.com
https://domain.com
到https://www.domain.com
What is wrong here and how can it be fixed? 这里有什么问题,如何解决?
Try : 试试:
RewriteEngine on
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^ https://www.example.com%{REQUEST_URI} [NE,L,NC,R=301]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.