Redirect to another server based on URL

I created a new website for a client that has an intranet integrated into my old website.

The new website is currently located on a different server, but when the domain A records point to the new server, the old site (and intranet) will obviously not be available, but I need to keep the active intranet. The path to their intranet: abc.com/intranet

Is there a way to direct the url for the old server? For instance:

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

If this is not possible, I suggest that I look for a subdomain on abc.com for the intranet. Any thoughts are welcome.

+6
source share
2 answers

You need to use Apache RewriteRule using mod_rewrite . It can be placed in a .htaccess file on your root server or it can be placed directly in your Apache configuration file.

If you want to redirect example.com to example.com/intranet , then this is Apache RewriteRule , which should work for your needs:

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

This will capture any URL on the site that the RewriteRule is RewriteRule , and redirect them to /intranet . This /intranet can also be a full URL, such as this example below:

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

EDIT:. Rereading my question, I am not 100% sure that the answer above works for you as it is. Therefore, I think that if you describe how to specify one URL from one server to another, you will do it. This installs on the new server:

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

To capture any URL coming from new_example.com/intranet and redirect it to old_example.com/intranet .

OTHER EDITING:. Since the original poster indicates that the server will completely change the IP address, the subdomain for the old server will be preferable. You cannot redirect content to the same domain as you describe if you completely switch domains to different IP addresses. Both servers must be active with the name of an active, but different domain, for what you want.

+1
source

abc.com/intranet is the path in the virtual file system provided by your web server, so it is not possible to serve content from another web server. You have 2 options.

  • Place the reverse proxy in front of both servers and receive content from server A or B based on the original client request.

  • As you said, create a subdomain as well as a redirect / intranet to the new subdomain.

Hope this help!

+1
source

Source: https://habr.com/ru/post/958078/


All Articles