Can apache redirect to a URL but mask the new URL

apache-2.2maskredirect

We're a bit green when it comes to this stuff and don't fully understand the answers found (we might also be using the wrong search terms).


Problem

We need to redirect a subdomain to another domain but mask the redirected domain.

So that this redirect:

subdomain.domain.com –> domain.com

Shows in the browser URL bar as:

subdomain.domain.com

And obviously any pages show correctly as:

subdomain.domain.com/page-name

Is this possible?


Research

Some answers we've found talk about URL re-writing and others talk about a proxy pass.

http://httpd.apache.org/docs/2.2/mod/mod_proxy.html

Redirects and masking with Apache

But we don't fully understand how to set those up – i.e. what exactly goes into each virtual host and a step by step?

Both domains will be hosted on the same server and we have access to the virtual hosts.

Any help or pointers in the right direction would be much appreciated.

Cheers

Ben

Best Answer

For security reasons, browsers won't let you spoof the URL shown in the address bar. So, if you need the bar to show "subdomain.domain.com", then the browser will need to be talking to a machine at the IP address returned by resolving "subdomain.domain.com".

If subdomain.domain.com and domain.com is being served on the same machine, then you could internally proxy requests from one to the other's server. You could even do this if the servers were on different (although hopefully "nearby") machines. However, the longer the path, the greater the performance penalty.

Related Topic