Search code examples
apache.htaccesshaproxy

Redirect to new domain from an existing domain (Apache / haproxy)


DESCRIPTION: We have two apache servers and one is behind haproxy. Our NEW server is behind the haproxy box, the OLD one is on a different network. I am going to create an apache rewrite rule to point this oldsite.com/some/thing to the new haproxy box (as seen below). This will redirect to newsite/some/other thing.

QUESTION: Is it possible to make this transparent to the user? I would like the user to only see oldsite.com/some/thing and not newsite/some/other/thing ? Is this achieveable with haproxy? I know a little about haproxy but not a lot. Thanks in advance for your time. much appreciated.

enter image description here


Solution

  • Based on the tip from @Panama Jack, I created a basic test which I think will work for me. This is just the rough config and requires protections and so forth to get working fully. This is apache 2.4 (amazon AMI). As you see above, I am wanting to make the second server transparent to the user.

    This example (quick and dirty) setup does the following:

    • login.HOST.info = login.DESTINATION.info
    • (user never sees the login.DESTINATION.info url that does the page actually exists on)

    Server Handling Request:

    <VirtualHost *:80>
        ServerAdmin admin@localhost
        ServerName login.HOST.info
        ServerAlias www.login.HOST.info
        ErrorLog logs/login-error_log
        CustomLog logs/login-access_log common
        RewriteEngine On
        RequestHeader add X-SSL off
        RewriteRule ^/(.*) http://login.DESTINATION.info/$1 [P,L]
    </VirtualHost>
    

    Final Server Handling the Request:

    <VirtualHost *:80>
        ServerName login.DESTINATION.info
        ServerAdmin webmaster@site.com
        DocumentRoot /var/www/deal/site/locator/whatever/
    
        RemoteIPHeader X-Forwarder-For    # allows the host to remain
        RemoteIPInternalProxy XXXX.0.0.0/8   # ip of other machine
    </VirtualHost>