0

I'm wondering how can use my server A to redirect different URL's to the respective server.
Here is my setup:

Server A: apache 2.4 on ubuntu 16
Server B: apache 2.4 on windows 2012

Port 80 is forwarded to server A on the firewall.
Let's say I want URL http://hr.xyz.com forwarded to https://hr.xyz.com on server B, how can I achieve this (notice change from port 80 to 443)?

I've been trying with ProxyPass & RewriteEngine (seperately, not at the same time) in my
000-default.conf but haven't had any success

ProxyPass
Server A:

<VirtualHost *:80>
ServerName hr.xyz.com
ProxyRequests Off

<Proxy *>
 Order deny,allow
        Allow from all
    </Proxy>

    ProxyPass / https://ip.from.server.B:443/
    ProxyPassReverse / https://ip.from.server.B:443/
    <Location />
        Order allow,deny
        Allow from all
    </Location>

</VirtualHost>

RewriteEngine:
Server A

On server A
<VirtualHost *:80>
ServerName hr.xyz.be


RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule ^/?(.*)$ https://hr.xyz.com/$1 [NE,L,R=301]
</VirtualHost>

Server B:

RewriteEngine on
    RewriteCond %{HTTP_HOST} !^hr.xyz.com$ [NC]
    RewriteRule ^/?(.*)$ https://hr.xyz.com/$1 [NE,L,R=301]

But I guess RewriteEngine is only meant to be configured on the same Apache server, not 2 as is my case.

Could someone advice me how to succeed please?

  • You might need to rewrite with a reverse proxy: httpd.apache.org/docs/2.4/rewrite/proxy.html – Stephen Ostermiller Jan 18 '18 at 20:00
  • "But I guess RewriteEngine is only meant to be configured on the same Apache server" - what do you mean by this? What is happening? What is the desired result? By "forwarding to https://...", are you wanting to send the response back over the original insecure HTTP connection? As opposed to an actual redirect? You can use mod_rewrite with mod_proxy as well, however, in your example you are issuing an external redirect. – DocRoot Jan 18 '18 at 20:22
  • @DocRoot: I mean that I think you can only use the RewriteEngine and the rules for http -> https only on the same server, not on 2 separate servers as in my case. The desired result is that people are redirected from hr.xyz.com to hr.xyz.com. The problem is, there is another site (with different url) on port 80 which still needs to be available. – WouterVE Jan 19 '18 at 14:46
  • It doesn't matter whether it's physically one server or two. mod_rewrite is not aware of this. What matters is where https://hr.xyz.com/ resolves to. So, it is an external redirect that you require? ie. the user is physically redirected from http://hr.xyz.com to https://hr.xyz.com? However, your use of the terms "forwarded" and "proxy" suggest otherwise? What do you want the user to see in the browsers address bar? – DocRoot Jan 19 '18 at 15:33
  • I'm still learning apache so excuse me if I misuse some terms like forward & proxy. What you describe is exactly what I want: the user types 'hr.xyz.com' which is then redirected to 'hr.xyz.com' (which is also the address in the browser. – WouterVE Jan 22 '18 at 8:24
1

I've solved this on a much simpler way than my initial thoughts. I've only used server B for this setup.

As described in the apache documentation, one can use redirect.

I added an extra virtualhost in de httpd.conf

<VirtualHost *:80>
            ServerName hr.xyz.com
            Redirect 301 / https://hr.xyz.com

This results in redirecting the url http://hr.xyz.com to https://hr.xyz.com which is exactly what I wanted!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.