Search code examples
apache.htaccesswebfaction

Improper redirection in apache for subdomain


I'm currently trying to redirect a webfaction app to another one hosted under a different URL.

This is what I've got so far

RewriteEngine On

RewriteCond %{HTTP_HOST} ^foo\.barbaz\.com$ [NC]
RewriteRule (.*) http://barbaz.com/foo%{REQUEST_URI} [R=permanent,L]

That works properly for anything like

http://foo.barbaz.com/noideawhatimdoing => http://barbaz.com/foo/noideawhatimdoing

But fails miserably when using only the root url.

http://foo.barbaz.com/ => http://foo.barbaz.com/absolute/path/to/folder/foo/absolute/path/to/folder/foo/absolute/path/to/folder/foo/...

Note that /foo is appended to the absolute path to the .htaccess file and that complete string is added multiple times to the resulting url, which has exactly the same HTTP_HOST.

I have tried RedirectBase and FollowSymLinks, but none seem to do the trick.

Any ideas? Really not an expert in apache, as you can tell.

Thanks.

A.


Solution

  • You need to make sure to place this permanent redirect as very first rule in your .htaccess so that this rule is not impacted by other rules.