Shijin T R Shijin T R - 29 days ago 16
Apache Configuration Question

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?

Answer

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