【问题标题】:Apache2 redirect https://example.com to https://www.example.com with vhostsApache2 使用虚拟主机将 https://example.com 重定向到 https://www.example.com
【发布时间】:2020-12-12 09:25:39
【问题描述】:

伙计们,

我有带有虚拟主机的 apache 服务器。

对于虚拟主机,我需要将http://*.example.com 重定向到https://*.example.com,它作为代码中的最后一个块工作。

注册。主服务器,我想将https://example.com, http://example.com & http://www.example.com 重定向到https://www.example.com

http://example.com & http://www.example.com 工作正常,但只有 https://example.com 不指导。

有什么想法吗?!

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]

谢谢,

【问题讨论】:

  • 让我知道我的答案是否有效。可能应该:D

标签: apache http web mod-rewrite https


【解决方案1】:

尝试改变:

RewriteCond %{HTTPS} on [OR]
RewriteCond %{HTTP_HOST} ^example\.com [NC] 
RewriteRule ^ https://www.%{HTTP_HOST}$1 [R=301,L]

到:

RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^example\.com [NC] 
RewriteRule ^ https://www.%{HTTP_HOST}$1 [R=301,L]

Cod3 快乐!

【讨论】:

  • @Nurhun 它必须确实有效。端口 443 配置到什么目录? http 和 HTTPS 显示不同的页面吗?
  • @Nurhun 你能把你的虚拟主机配置粘贴到这里吗?
猜你喜欢
  • 2015-09-25
  • 1970-01-01
  • 2020-09-24
  • 2011-07-06
  • 2011-08-12
  • 1970-01-01
  • 1970-01-01
  • 2016-11-17
  • 1970-01-01
相关资源
最近更新 更多