简体   繁体   English

Apache2 使用虚拟主机将 https://example.com 重定向到 https://www.example.com

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

相关问题 htaccess重定向https:// www。 (https://www.example.com)到非www(https://example.com) - htaccess redirect https://www. (https://www.example.com) to non www (https://example.com) 如何将https://example.com/重定向到https://www.example.com/ - How to Redirect https://example.com/ to https://www.example.com/ 如何将 https://www.example.com/aaa 重定向到 https://example.com/aaa/ - how to redirect https://www.example.com/aaa to https://example.com/aaa/ http://example.com不会重定向到https://www.example.com - http://example.com would not redirect to https://www.example.com 解析 http://www.example.com 以通过 htaccess 永久重定向到 https://example.com - Resolving http://www.example.com to permanently redirect to https://example.com via htaccess 如何将 http://www.example.com 重定向到 https://example.Z4D236D9A2D102C5ZFE6AD1Cware - How to redirect http://www.example.com to https://example.com with middleware 全部重定向到 https://www.example.com - Redirect all to https://www.example.com 将* .example.com和example.com重定向到HTTPS的www.example.com时出现问题 - Problem with redirecting *.example.com & example.com to www.example.com for HTTPS 强制从 https://example.com 重定向到 https://www.example.com - force redirection from https://example.com to https://www.example.com httpd.conf将https://example.com重写为https://www.example.com - httpd.conf rewrite https://example.com to https://www.example.com
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM