简体   繁体   English

通过htaccess将所有流量重定向到https://www.domain.com

[英]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.comhttps://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.

相关问题 使用.htaccess将http://www.domain.com重定向到https://www.domain.com - Redirect http://www.domain.com to https://www.domain.com using .htaccess 如何使用.htaccess将所有http流量重定向到https和www.domain.com - how to use .htaccess to redirect all http traffic to https AND www.domain.com 如何使用.htaccess通过HTTP和HTTPS将传入请求从domain.com重定向到www.domain.com? - How do I redirect incoming requests from domain.com to www.domain.com via HTTP and HTTPS using .htaccess? SSL错误:如何通过.htaccess将https://www.domain.com重定向到http://domain.com以避免SSL错误 - SSL Error: how to redirect https://www.domain.com to http://domain.com via .htaccess to avoid SSL error 如何将domain.com或www.domain.com重定向到https www.domain.com - How to redirect domain.com or www.domain.com to https www.domain.com .htaccess-将domain.com和www.domain.com重定向到www.domain.com/en - .htaccess - redirect domain.com and www.domain.com - to www.domain.com/en 将URL https://www.domain.com重定向到https://www.domain.com/ - redirect the URL https://www.domain.com into https://www.domain.com/ .htaccess将domain.com重定向到www.domain.com - .htaccess redirect domain.com to www.domain.com 使用htaccess将domain.com重定向到www.domain.com - redirect domain.com to www.domain.com with htaccess 将http://www.domain.com重定向到https://domain.com - redirect http://www.domain.com to https://domain.com
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM