John John - 1 year ago 127
Apache Configuration Question

rewrite subdomain using .htaccess

My main domain is

, and I want to rewrite all the traffic from
to the first one. Meaning if someone accesses
, he actually accesses
, however, he's still shown
in the browser's navigation bar.

I did some research, but I couldn't find something too promising.

Answer Source

You don't need rewriting for this, in fact internal rewriting is not possible between separate hosts...

Assuming that both "subdomains" (those are actually hostnames) are served by the same http server you can simply configure the same DocumentRoot for both hosts. That way they serve exactly the same file system which obviously means that the same scripts will be called.

Maybe you can get away even more simple if you just use the ServerAlias command for your virtual host. This obviously is only possible if you do not need separate configurations for both hosts.

Just take a look into the documentation of the apache http server. This is explained and good examples are offered:

In case those two hosts are not served by the same http server you could use an internal proxy setup: subdomain1.domain.tld acts as a front end proxy for subdomain.domain.tld, so it just relays all incoming requests and also the outgoing responses. That is easily done with a combination of the ProxyPass and the ProxyPassReverse rules offered by apaches proxy module:

This setup can even be used if the two http servers operate on different IP addresses or even completely separate systems.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download