Apache domain redirect between virtualservers

222 Views Asked by At

I've got one dedicated server which I splitted into more virtual servers. On main server I use standard port for http (80), but for others I was forced to set different ports. But I've got some spare domains. What is best way to make invisible redirect to another server when user come through specific domain? I don't want to use iframes or redirect to another website. I would like domain to act like on shared web hostings. But with different servers.

Is it possible to do? I know that apache gets information about from which domain user came. I would like to do it with virtual hosts if it's possible.

<VirtualHost *>
ServerName mydomain
ServerAlias mydomain 
some redirection
CustomLog /var/log/apache2/mydomain.access.log combined
ServerAdmin myemail
</VirtualHost>

Thanks in advance :]

1

There are 1 best solutions below

0
On BEST ANSWER

Since you have access to the server's config, take a look at the ProxyPass, ProxyPassMatch, and ProxyPassReverse directives that are part of mod_proxy. You'll need to make sure the module is loaded before you can use these directives.

In general, in your mydomain config, say you want to have visitors see the site at http://myother.domain.com/ when they go to http://mydomain/other, you'd just add:

ProxyPass /other http://myother.domain.com/
ProxyPassReverse /other http://myother.domain.com/

The ProxyPassReverse is to ensure proxied location responses get rewritten. For example, if a page at http://myother.domain.com/ returned a 301 redirect to http://myother.domain.com/newimage.gif, this directive will internal rewrite the response's location from http://myother.domain.com/newimage.gif to http://mydomain/other/newimage.gif, for it to be proxied again.

If you have cookie domains that also need rewriting, take a look at ProxyPassReverseCookieDomain and ProxyPassReverseCookiePath.