redirect to another domain, but keep the url [duplicate]

纵饮孤独 提交于 2019-12-24 02:54:08

问题


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?


回答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.




回答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




回答3:


You can just serve a page from example2.com that uses javascript or an iframe to load the content from example1.com



来源:https://stackoverflow.com/questions/10457207/redirect-to-another-domain-but-keep-the-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!