【问题标题】:RewriteRules redirect specific domain https to http, opposite for the othersRewriteRules 将特定域 https 重定向到 http,其他域相反
【发布时间】:2020-12-13 01:32:53
【问题描述】:

我有一个域名为 example.info 的网站。最近我获得了两个新域名:example.com 和 example.org。

我在 example.info 上有一个 SSL 证书,我将所有 http 重定向到 https,如下所示:

  RewriteCond %{HTTPS} off
  RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

现在我希望 example.com 成为主要 url,另外两个我只想重定向到 example.com。

我将 SSL 证书从 .info 更改为 .com,一切都很好,但我的问题是,例如 Google 从 https://example.info 链接我,现在它失败了,因为该 url 没有 SSL 证书了。所以我想做的是将https://example.info重定向到https://example.com

我尝试了不同的方法,但这是不起作用的解决方案之一。

  RewriteCond %{HTTPS} off
  RewriteCond %{REQUEST_URI} !^(www\.)?example\.info$
  RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
 
  RewriteCond %{HTTPS} on
  RewriteCond %{HTTP_HOST} ^(www\.)?example\.info$
  RewriteRule ^ https://example\.com [L,R=301]

我做错了什么?如何实现将 https://example.info 重定向到 https://example.com 并保持重定向到 https for example.com?

//// 编辑

如果我因为没有有效证书而无法重定向https://example.info,如何防止在我写http://example.info 时它被重定向到https?

【问题讨论】:

  • 如果https://example.info 没有有效的 ssl 证书,则无法重定向。
  • 谢谢。那么当你不想再拥有证书时有什么解决方案吗?

标签: .htaccess mod-rewrite


【解决方案1】:

我认为你能做的最好的就是:

RewriteCond %{HTTP_HOST} ^(www\.)?example\.(info|org)$
RewriteRule ^ https://example\.com%{REQUEST_URI} [L,R=301]

RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

【讨论】:

  • 我最终做了这样的事情,因为其他原因它仍然会尝试重定向到example.info,但我接受你的回答,因为它让我走上了正确的轨道。 RewriteCond %{HTTPS} 关闭 RewriteCond %{REQUEST_URI} ^(www\.)?example\.com$ RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] RewriteCond %{HTTP_HOST} ^ (www\.)?example\.info$ RewriteRule ^ example\.com/$1 [R=301,L]
猜你喜欢
  • 1970-01-01
  • 2016-01-30
  • 1970-01-01
  • 2016-08-12
  • 2016-05-09
  • 2015-04-01
  • 1970-01-01
  • 2015-05-19
  • 2015-08-26
相关资源
最近更新 更多