简体   繁体   English

根据网址路径重定向到其他服务器

[英]redirect to different server based on url path

I've made a new website for a client who has an intranet integrated into their old website. 我为一个将Intranet集成到其旧网站中的客户创建了一个新网站。

The new website is currently on a different server, but when the domain A records point to the new server, the old site (and intranet) will obviously not be accessible, but I need to keep their intranet active. 新网站当前位于另一台服务器上,但是当域A记录指向新服务器时,显然将无法访问旧站点(和Intranet),但是我需要保持其Intranet处于活动状态。 The path to their intranet is: abc.com/intranet 他们的Intranet的路径是: abc.com/intranet

Is there a way to have URL path direct to the old server? 有没有办法将URL路径直接指向旧服务器? For example: 例如:

abc.com - new website loads on new server

abc.com/intranet - old website loads on older server

If it's not possible, I suppose I'm looking at creating a sub-domain on abc.com for the intranet. 如果不可能,我想我正在考虑在abc.com为内部网创建一个子域。 Any thoughts are appreciated. 任何想法表示赞赏。

You need to use an Apache RewriteRule using mod_rewrite . 您需要使用使用mod_rewrite的Apache RewriteRule This can be placed in an .htaccess file on your server's root or it can be placed directly into your Apache config file. 可以将其放置在服务器根目录下的.htaccess文件中,也可以直接将其放置在Apache配置文件中。

If you want to redirect example.com to example.com/intranet , then this is the Apache RewriteRule that should work for your needs: 如果要将example.com重定向到example.com/intranet ,则这是应该满足您需求的Apache RewriteRule

RewriteEngine on
RewriteRule ^(.*)$ /intranet [L,R=301]

This will grab any URL on the site this RewriteRule is placed on & redirect them to /intranet . 这将获取放置RewriteRule的网站上的任何URL并将它们重定向到/intranet That /intranet can also be a full URL such as this example below: /intranet也可以是完整的URL,例如以下示例:

RewriteEngine on
RewriteRule ^(.*)$ http://example.com/intranet [L,R=301]

EDIT: Upon rereading your question, I am not 100% sure the answer above works for you as-is. 编辑:重新阅读您的问题后,我不是100%确定上面的答案对您仍然有效。 So I think if you are describing how to point one URL path from one server to another, you would do this. 因此,我认为如果您要描述如何将一个URL路径从一台服务器指向另一台服务器,则可以这样做。 This gets placed on the new server: 这放置在新服务器上:

RewriteEngine on
RewriteRule ^/intranet(.*)$ http://old_example.com/intranet [L,R=301]

That would grab any URL coming from new_example.com/intranet and redirect it to old_example.com/intranet . 这将获取来自new_example.com/intranet所有URL,并将其重定向到old_example.com/intranet

ANOTHER EDIT: Since the original poster indicates the server will have the IP fully changed, then a subdomain for the old server is the best way to go. 另一个编辑:由于原始张贴者指示服务器将完全更改IP,因此最好的方法是使用旧服务器的子域。 You can't redirect content on one domain the way you describe if you switch the domains fully to different IP. 如果将域完全切换到其他IP,则无法按照描述的方式重定向一个域上的内容。 Both servers need to be active with an active—but different—domain name for what you want to happen. 两台服务器都必须处于活动状态,并且要使用一个活动的但不同的域名才能实现。

abc.com/intranet is a path in the virtual file system exposed by your web server, so is not possible to serve the content from different web server. abc.com/intranet是Web服务器公开的虚拟文件系统中的路径,因此无法从其他Web服务器提供内容。 You have 2 options here. 您在这里有2个选项。

  1. Put a reverse proxy in front of both servers and get the content from server A or B based on the original client request. 将反向代理置于两个服务器的前面,并根据原始客户端请求从服务器A或B获取内容。

  2. As you said, create a subdomain and also redirect /intranet to the new subdomain. 如您所说,创建一个子域,并将/ intranet重定向到新的子域。

Hope this help! 希望有帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM