Andrew
Andrew

Reputation: 8090

Apache mod rewrite to direct from one server to another

I've got to apache web servers running. One on port 80 and another on port 8077.

I'm wanting to try and redirect all the traffic through the port 80 version if possible.

What I'm ideally wanting is to be able to go to http://translate.example.com and the traffic get directed to http://www.example.com:8077

I've already got a lot of mod_rewrite going on at the main port 80 server, but I'm not sure which of the servers needs configuration or whether both do.

I'm wanting to make sure that translate.example.com/img (or any other subdirectory) actually points to the 8087/images directory.

update

I've now got the following:

RewriteCond %{HTTP_HOST} example[NC]
RewriteCond %{REQUEST_URI} ^/glot$ [NC]
RewriteRule    ^(.*)$  http://www.example.com:8077/$1  [P]
ProxyPassReverse / http://www.example.com/

I'm getting to see the other servers new pages, but I'm finding all the resources aren't found like images, css etc

Doing a view source all the resources in the installed product are set with leading slash

For example

/img/glotpress-logo.png

So I'm not sure how to get the resources loaded up. Note I'm happy enough if the original starting point is www.example.com/glot instead of glot.example.com as in the original question

Upvotes: 1

Views: 5944

Answers (2)

Amirul Ali
Amirul Ali

Reputation: 11

You can remap your resources to another server but having the other server on non-default port might prevent some of your visitors from viewing them as they might be block (firewalled) from accessing the port. If you're not worry about the port being block you can use mod_rewrite Remapping Resources. method.

RewriteEngine On
RewriteRule ^/images/(.+) http://www.example.com:8077/images/$1 [R,L]

If you want to make sure that everyone is able to view the external resources, you need to use proxy where apache will tunnel the visitor connection to example.com:8077 transparently. You can read more about mod_rewrite for Proxying at apache website.

RewriteEngine  on
RewriteBase    /images/
RewriteRule    ^images/(.*)$  http://example.com:8077/images/$1  [P]
ProxyPassReverse /images/ http://example.com/images/

UPDATE

Have you tried to remove

RewriteCond %{HTTP_HOST} example[NC] 

This line basically tells that it will only process if the HTTP_POST is example.com if its coming from www.example.com this rule is not applicable. I'm hoping that "example[NC]" is a typo.

In the end it probably looks like

RewriteRule ^/glot/(.*)$ http://www.example.com:8077/glot/$1 [P] 
ProxyPassReverse /glot/ http://www.example.com:8077/glot/

Upvotes: 1

Peter Wooster
Peter Wooster

Reputation: 6089

You need to do the configuration at the port 80 server to make it act as a proxy for the 8077 server.

The Apache document is here: http://httpd.apache.org/docs/trunk/rewrite/proxy.html

Upvotes: 0

Related Questions