【问题标题】:.htaccess redirect http and https subdomain to other domain.htaccess 将 http 和 https 子域重定向到其他域
【发布时间】:2016-01-14 11:57:30
【问题描述】:

我有子域:subdomain.example.com

我想将 http 和 https 重定向到另一个域

 http://subdomain.example.com --> https://subdomain.exampleNew.com
 https://subdomain.example.com --> https://subdomain.exampleNew.com

有人知道怎么做吗?

目前我只有:

 RewriteCond %{HTTP_HOST} ^subdomain.example.com$ [NC]
 RewriteRule ^(.*)$ https://subdomain.exampleNew.com/$1 [R=301,L]

【问题讨论】:

  • 那么真正的问题是什么?
  • 你的规则应该可以正常工作,如图所示。
  • 你说得对,那是不同的问题,我的域 .example.com 没有 ssl 并且在输入 subdomain.example.com 时出现 ssl 错误。现在我知道在 ssl 检查之前不会触发 httacces。

标签: .htaccess redirect


【解决方案1】:

如果要保留http/https状态,需要先捕获状态,然后以%1的形式传递给规则。请改用以下内容:

RewriteCond %{HTTPS}s ^on(s)|off
RewriteCond %{HTTP_HOST} ^subdomain.example.com$ [NC]
RewriteRule ^(.*)$ http%1://subdomain.exampleNew.com/$1 [R=301,L]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-03-03
    • 1970-01-01
    • 2020-04-21
    • 2016-08-12
    • 2015-05-19
    • 1970-01-01
    • 1970-01-01
    • 2015-12-24
    相关资源
    最近更新 更多