R – .htaccess redirect www.domain.com to sub.domain.com but only for root

.htaccessapacheredirect

I have two parts to a site, foo.domain.com and bar.domain.com (with bar.domain.com really being a CNAME to another host) I want users entering www.domain.com to be redirected to bar.domain.com. That is a simple redirect, no problem.

However I also want to be able to access subfolders of www.domain.com, is there a way the .htaccess file can be configured for this?

Best Answer

This is a simple redirect. The only trick is that Redirect acts on a prefix, so you couldn't use it to match only / on its own. RedirectMatch does not have that limitation.

RedirectMatch permanent ^/$ http://bar.domain.com/
Related Topic