Apache有条件地将子域重定向到主域

时间:2016-11-10 11:32:21

标签: apache ubuntu redirect

我有一个域和一个子域,如cloud.example.com和example.com。

我需要使用以下条件将所有cloud.example.com重定向到example.com。

cloud.example.com to www.example.com/customers/login

cloud.example.com/<any url>  to www.example.com/<any url>

我已在我的cloud.example.com的apache配置文件中添加了以下代码

ServerName cloud.example.com
Redirect 301 / https://www.example.com/customer/login

现在,cloud.example.com已成功重定向到https://www.example.com/customer/login,但所有其他网页都无效。这是重定向到www.example.com/customer/login

如何解决这个问题?

1 个答案:

答案 0 :(得分:2)

最好的方法是使用重写规则。

RewriteRule ^/$ https://www.example.com/customer/login [R]
RewriteRule ^/(.+) https://www.example.com/$1 [R]

别忘了添加模块并启用RewriteEngine

相关问题