My idea is:
- requests to service.example.com should be redirected to service.example.com,
- all the other requests to example.com should be redirected to base.example.com
My host is configured in such a way, that there is example.com directory, and all subdomains live in their subdirectories (example.com/service, example.com/base, etc.).
How can I achieve the needed redirections?
I have tried with RedirectMatch, RewriteCond, RewriteRule, but with no results. My try was:
RewriteCond %{HTTP_HOST} ^service\.example\.com$ [NC] RewriteRule ^(.*)$ http://service.example.com/$1 [R=301,L] RewriteCond %{HTTP_HOST} !^base\.example\.com$ [NC] RewriteRule ^(.*)$ http://base.example.com/$1 [R=301,L] It worked only for the base.example.com. For service.example.com, there was loop of rewrites/redirections.
I could only find examples of simple rewrites, one domain -> other domain, or many domains -> one domain, yet my case is different: its many domains -> many other domains.
EDIT: OK, I got it with:
RewriteCond %{HTTP_HOST} ^service\.example\.com$ [NC] RewriteRule ^(.*)$ - [L] RewriteCond %{HTTP_HOST} !^base\.example\.com$ [NC] RewriteRule ^(.*)$ http://base.example.com/$1 [R=301,L] The key was to use a rule to do nothing: - [L].