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 :]
Since you have access to the server's config, take a look at the
ProxyPass
,ProxyPassMatch
, andProxyPassReverse
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 tohttp://mydomain/other
, you'd just add:The
ProxyPassReverse
is to ensure proxied location responses get rewritten. For example, if a page athttp://myother.domain.com/
returned a 301 redirect tohttp://myother.domain.com/newimage.gif
, this directive will internal rewrite the response's location fromhttp://myother.domain.com/newimage.gif
tohttp://mydomain/other/newimage.gif
, for it to be proxied again.If you have cookie domains that also need rewriting, take a look at
ProxyPassReverseCookieDomain
andProxyPassReverseCookiePath
.