.htaccess - RewriteRules 将特定域 https 重定向到 http,其他域相反
问题描述
我有一个域名为 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?
解决方案
我认为你能做的最好的就是:
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]
推荐阅读
- python - Python:将Dataframe分配给第二个变量,改变第二个DataFrame会改变第一个
- matlab - 如何使simulink过程在循环中重复?
- c++11 - 检查两棵树是否具有相同的结构
- django - Django 总是尝试使用 root 用户连接到 Mysql
- scala - 如何在scala中创建和匹配模式
- javascript - Webdriverio 使用 WebStorm 调试 BDD 测试
- r - 安排删除数据框行名
- jquery - click() if ($("[id*='string']")) show()
- c - 更改从未到达的行时发生堆栈溢出 - 为什么以及如何防止它?
- android - android矢量的中心路径