[英]Apache2 redirect https://example.com to https://www.example.com with vhosts
Folks,各位,
I have apache server with vhosts.我有带有 vhosts 的 apache 服务器。
For vhosts, I need to redirect http://*.example.com
to https://*.example.com
and it works as last block in the code.对于虚拟主机,我需要将
http://*.example.com
重定向到https://*.example.com
,它作为代码中的最后一个块工作。
Reg.注册。 the main server, I want to redirect
https://example.com
, http://example.com
& http://www.example.com
to https://www.example.com
主服务器,我想将
https://example.com
、 http://example.com
和http://www.example.com
重定向到https://www.example.com
http://example.com
& http://www.example.com
works fine but only https://example.com
not directing. http://example.com
& http://www.example.com
工作正常,但只有https://example.com
没有定向。
Any ideas ?!有任何想法吗 ?!
RewriteEngine On
# Redirect https://example.com to https://www.example.com #(NOT WORKING)
RewriteCond %{HTTPS} on [OR]
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^ https://www.%{HTTP_HOST}$1 [R=301,L]
#RewriteRule ^/(.*)$ https://www.example.com [R=301,L]
# Redirect http://example.com to https://www.example.com #(WORKING)
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^ https://www.%{HTTP_HOST}$1 [R=301,L]
# Redirects http://*.example.com to https://*.example.com #(WORKING)
RewriteCond %{HTTPS} !=on [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Thanks,谢谢,
Try changing:尝试改变:
RewriteCond %{HTTPS} on [OR]
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^ https://www.%{HTTP_HOST}$1 [R=301,L]
to:到:
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^ https://www.%{HTTP_HOST}$1 [R=301,L]
Happy Cod3ing!快乐鳕鱼!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.