从域B上的域A获取内容

时间:2020-12-30 10:43:12

So let's say I have two domains: www.foo.com and www.bar.com. They are on seperated servers (for now, that could be changed) and we've built a new site for the bar content that you can access now by www.foo.com/bar

所以,假设我有两个域名:www.foo.com和www.bar.com。它们位于分离的服务器上(目前可以更改)我们为条形码内容构建了一个新站点,您现在可以访问www.foo.com/bar

As far, as good, every thing is working. But now we want to display the bar content at www.bar.com. If we'd just make a C-Name we would still have to type www.bar.com/bar which is kind of strange.

到目前为止,每件事都有效。但现在我们想在www.bar.com上显示酒吧内容。如果我们只是制作一个C-Name,我们仍然需要输入www.bar.com/bar这有点奇怪。

What can we do to get the content of www.foo.com/bar ar www.bar.com (of course www.foo.com/bar/baz/123 should be available at www.bar.com/baz/123 and so on)

我们如何才能获得www.foo.com/bar ar www.bar.com(当然www.foo.com/bar/baz/123)的内容,请访问www.bar.com/baz/123和等等)

2 个解决方案

#1


If you don't want to redirect, then you will have to proxy on www.bar.com using [P] Flag. So on your www.bar.com server .htaccess you should be able to do something like this.

如果您不想重定向,则必须使用[P] Flag在www.bar.com上进行代理。所以在你的www.bar.com服务器上.htaccess你应该可以做这样的事情。

RewriteEngine On
RewriteRule ^(.*) http://www.foo.com/bar/$1 [P]

http://httpd.apache.org/docs/current/rewrite/flags.html#flag_p

Note: mod_proxy is required and needs to be enabled in Apache if not already.

注意:mod_proxy是必需的,如果没有,则需要在Apache中启用。

#2


Try this in your htaccess

在你的htaccess中尝试这个

 RedirectMatch 301 ^/(.*)/?$ http://www.bar.com/$1

The above example redirects the entire site to domain b.

以上示例将整个站点重定向到域b。

If you want to redirect /bar requests to domain B , then try the following

如果要将请求重定向/禁止到域B,请尝试以下操作

 RedirectMatch 301 ^/bar/(.*)/?$ http://www.bar.com/$1

#1


If you don't want to redirect, then you will have to proxy on www.bar.com using [P] Flag. So on your www.bar.com server .htaccess you should be able to do something like this.

如果您不想重定向,则必须使用[P] Flag在www.bar.com上进行代理。所以在你的www.bar.com服务器上.htaccess你应该可以做这样的事情。

RewriteEngine On
RewriteRule ^(.*) http://www.foo.com/bar/$1 [P]

http://httpd.apache.org/docs/current/rewrite/flags.html#flag_p

Note: mod_proxy is required and needs to be enabled in Apache if not already.

注意:mod_proxy是必需的,如果没有,则需要在Apache中启用。

#2


Try this in your htaccess

在你的htaccess中尝试这个

 RedirectMatch 301 ^/(.*)/?$ http://www.bar.com/$1

The above example redirects the entire site to domain b.

以上示例将整个站点重定向到域b。

If you want to redirect /bar requests to domain B , then try the following

如果要将请求重定向/禁止到域B,请尝试以下操作

 RedirectMatch 301 ^/bar/(.*)/?$ http://www.bar.com/$1