Apache redirect based on hostname [duplicate]

Solution 1:

Are you running multiple instances of Apache, each listening on a different port? Why? Virtual hosts will take care of everything.

http://httpd.apache.org/docs/2.2/vhosts/name-based.html

Solution 2:

Follow the documentation about canonical hostnames which lead to <If> directive :

<If "%{HTTP_HOST} == 'build.mydomain.com' && %{SERVER_PORT} -eq 80">
    RedirectMatch permanent /.* http://build.mydomain.com:8111
</If>

<If "%{HTTP_HOST} == 'www.mydomain.com' && %{SERVER_PORT} -eq 80">
    RedirectMatch permanent /.* http://www.mydomain.com:8080
</If>

...

Solution 3:

Actually, I doubt using redirect is winning strategy for what you're trying to do. I'd recommend using mod_proxy to create a reverse proxy which will hide the way you've built your system.

And if I had the choice, I would use something more lightweight and more convenient to configure, like Perlbal.