简体   繁体   中英

Apache redirect sub domain to main domain conditionally

I have one domain and a sub domain like cloud.example.com and example.com.

I need to redirect all cloud.example.com to example.com with the following condition.

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

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

I have added the bellow code in my apache config file of cloud.example.com

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

Now cloud.example.com successfully redirecting to https://www.example.com/customer/login but all other pages are not working .That are redirecting to www.example.com/customer/login

How to solve this issue?

The best way is to use rewrite rules.

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

Dont forget to add the module and enable the RewriteEngine

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM