-1

I am in the middle of moving an application from one server to another in our corporate network. The current production url is http://example1.mycompany.com. We have copied everything onto the new server and can access it using http://example2.mycompany.com. Our team has done our testing to ensure everything is working properly, but we want a fall-back strategy in case the move doesn't work under the typical application load. It can take several days to have our internal dns records changed, so before requesting that example1.mycompany.com be pointed to the new server, I was hoping I could use an .htaccess file with either mod_rewrite or mod_proxy to redirect traffic to the new server without the users knowing that anything has changed so they can copy urls and send them in email as usual.

The other caveat is that in order to authenticate to the application we go through a single signon page and the protocol changes from http to https.

I have tested both suggestions from jpiddle888 but neither of them keeps the browser's address bar looking like it is pointing to the old production server.

Any help would be appreciated.

4
  • A redirect is an instruction from the web server to a web browser: this resource can be found elsewhere, retry your request with with URI Location such-and-such and this will show a changed URI in the browser. - When you don't want that, you typically configure a "reverse proxy" , where the web server hosting the URI in the original request (example1.com) makes a second request , retrieves the result from a different server (example2.com) and returns the response it receives to the site visitor. This can increase latency and will increase the bandwidth uses for example1.com
    – HBruijn
    Commented Apr 8 at 5:48
  • Note that depending on how content and cookies etc are set on example2.com , a simple reverse proxy may break the user experience.
    – HBruijn
    Commented Apr 8 at 5:50
  • Your question is very confused. You conflate hosts with sites, sites with URLs, redirection with rewriting.You seem to be trying to redirect when that is explicitly what you say you don't want to do.
    – symcbean
    Commented Apr 8 at 10:31
  • Be aware that permanent redirects are cached by web browsers. When you have been testing with redirects and then make changes in your configuration, always launch and test from a new incognito/private browser window after every change or you won’t see the effects of your changed configuration
    – HBruijn
    Commented Apr 9 at 4:03

2 Answers 2

1

You're trying to use the Redirect directive instead of the RewriteRule directive (and there is no Rewrite ON directive).

If you want to keep the URL the same in the client's browser, you will need to proxy the requests to the new server. This can be done with either mod_rewrite or mod_proxy, depending on how flexible you need the matching to be.

mod_rewrite:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?example1\.com$ [NC]
RewriteRule ^/(.*) "http://example2.com/$1" [P]

mod_proxy:

ProxyPass        / http://example2.com/
ProxyPassReverse / http://example2.com/
3
  • I tried both methods on a test server. Both options redirected to the new server, but neither kept the browser's address bar looking like the old server.
    – draikes
    Commented Apr 8 at 17:32
  • Are you sure it's not the new server that is doing the redirect based on some other criteria? An Apache proxy does the request internally and passes along the results.
    – jpiddle888
    Commented Apr 9 at 15:06
  • @draikes Try adding ProxyPreserveHost On along with the ProxyPass lines.
    – doneal24
    Commented Apr 9 at 16:12
0

You can use mod_proxy together with mod_rewrite to achieve this

RewriteEngine On
RewriteCond %{HTTP_HOST} ^example1\.mycompany\.com$ [NC]
RewriteRule ^(.*) RewriteEngine On
RewriteCond %{HTTP_HOST} ^example1\.mycompany\.com$ [NC]
RewriteRule ^(.*)$ https://example2.mycompany.com/$1 [P,L]

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .