redirect to another domain, but keep the url

11,092

Solution 1

Yes it's possible.

I suggest reverse-proxy to do that. A software like NGinX does it very well, as well as apache of course (mod_proxy I recall).

Anyway, the downside of that approach is that your server (on www.example2.com) would request the page from example1 and send it through itself, and not directly from example1.

By the way - this technique is being used for load balancing as well.

Edit #1:
In nginx it's called ngx_http_upstream_module.

Edit #2:
grahaminn is correct yet my approach displays URL "correctly" - instead of one fixed URL which would make problems of, for example, bookmark a specific page.

Solution 2

Two options:

  1. Use Apache ProxyPass: http://httpd.apache.org/docs/2.2/mod/mod_proxy.html#proxypass
  2. Use Rewrite with [P] flag (requires mod_proxy installed)

    RewriteRule /(.*)$ http://example2.com/$1 [P]

http://httpd.apache.org/docs/2.4/rewrite/flags.html

Share:
11,092
Moshe Shaham
Author by

Moshe Shaham

Node.js, Java Javascript, Angular, Typescript

Updated on June 04, 2022

Comments

  • Moshe Shaham
    Moshe Shaham almost 2 years

    I have 2 vhosts: www.example1.com and www.example2.com

    I have a page on www.example1.com/page.html

    I want this page to be accessible in the other domain, meaning I want people to be able to get to www.example2.com/page.html and view that page that is physically on the other vhost. But the URL must display www.example2.com

    I don't want to simply move the page physically to the other vhost, because it is a wordpress page and it would be a huge hassle.

    Is this possible?