简体   繁体   English

将 https://domain.com 重定向到 https://www.domain.com

[英]redirecting https://domain.com to https://www.domain.com

I've recently moved my site to HTTPS and im trying to force all http traffic to https and also to the www.我最近将我的网站移至 HTTPS,我试图将所有 http 流量强制为 https 和 www。 version版本

ie forcing https://domain.com to https://www.domain.com即强制https://domain.comhttps://www.domain.com

I have this in my htaccess and all http to https works, apart from the redirect from https://domain.com to https://www.domain.com我有这个在我的htaccess以及所有HTTP到https的作品,除了从重定向https://domain.comhttps://www.domain.com

What am i doing wrong?我究竟做错了什么?

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

You need an OR condition here:你需要一个OR条件:

RewriteEngine  on

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.domain.com%{REQUEST_URI} [R=301,L,NE]
RewriteEngine  on

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.example.com%{REQUEST_URI} [R=301,L,NE]

with the above rule https://example.com was not redirecting to https://www.example.com .使用上述规则https://example.com没有重定向到https://www.example.com For that to happen I have added the following rule too in the apache ssl vhost block为此,我也在 apache ssl vhost 块中添加了以下规则


RewriteEngine  on
RewriteCond %{HTTP_HOST} !^www\. [NC] 
RewriteRule ^ https://www.exmple.com%{REQUEST_URI} [R=301,L,NE]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将http://www.domain.com重定向到https://domain.com - redirect http://www.domain.com to https://domain.com apache redrict 301从https://www.domain.com到https://domain.com - apache redrict 301 from https://www.domain.com to https://domain.com 在Apache 2中将domain.com重定向到www.domain.com - redirecting domain.com to www.domain.com in Apache 2 http to https AND //domain.com to www.domain.com AND subdomain.domain.com to subdomain.domain.com through htaccess - http to https AND //domain.com to www.domain.com AND subdomain.domain.com to subdomain.domain.com through htaccess 将域https://domain.com重定向到https://www.domain.com而无需重写规则,只需在apache中进行重定向 - Redirect domain https://domain.com to https://www.domain.com without rewrite rules just redirect in apache https:// 域 .com 重定向到 https:// www - https:// domain .com redirecting to https:// www 如何使用.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 使用.htaccess将http://www.domain.com重定向到https://www.domain.com - Redirect http://www.domain.com to https://www.domain.com using .htaccess 在Apache中将domain.com/folder重定向到www.domain.com/folder? - Redirecting domain.com/folder to www.domain.com/folder in Apache?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM