0

In Apache 2.4.39, I am unable to get http to https redirection working when also reverse proxying and the context path matches.

For example, I want http://www.example.com/foo to redirect to https://www.example.com/foo when "ProxyPass /foo" is also present.

I have followed the advice here, which is quite standard based on googling: https://stackoverflow.com/a/21798882/4410356

So I basically have:

<VirtualHost *:80>
  ServerName www.example.com
  Redirect / https://www.example.com/
</VirtualHost>

<VirtualHost *:443>
  ServerName www.example.com
  # ... SSL configuration here ...
  ProxyPass               /foo http://localhost:9999/foo
  ProxyPassReverse        /foo http://localhost:9999/foo
</VirtualHost>

However, the redirect from http to https seems to only work if there is no matching ProxyPass path. For example:

http://example.com/foo => http://example.com/foo
http://example.com/bar => https://example.com/bar

The following Rewrite rules work, but Apache recommends against using Rewrite:

RewriteCond %{HTTPS} !=on
RewriteRule "^/?(.*)" https://galaxy.erdc.hpc.mil/$1 [R,L]

Apache docs also states:

In the case of the http-to-https redirection, the use of RewriteRule would be appropriate if you don't have access to the main server configuration file, and are obliged to perform this task in a .htaccess file instead.

but this is not the case for me (I have access to the configuration files).

Is it possible to get http redirection working in this setup without using Rewrite rules?

  • As a comment, as far as I am aware, it should be possible to have /foo and /foo/ (i.e. multiple ProxyPass/ProxyPassReverse directives). – Anaksunaman Aug 11 at 22:41
  • @Anaksunaman Yes, that is possible and it does work as far as reverse proxying, but doesn't solve my problem for a ProxyPass match not being redirected (http -> https). – Phil Brown Aug 12 at 22:21
0

Try the same config but with a Location parameter to break out your ProxyPass config

<VirtualHost *:443>
  ServerName www.example.com
  # ... SSL configuration here ...
 <Location "/foo/">
   ProxyPass               http://localhost:9999/foo
   ProxyPassReverse        http://localhost:9999/foo
 </Location>
</VirtualHost>
  • It appears that using Location results in the same behavior. I initially thought it worked because I entered example.com/foo (no trailing slash) and it redirected to https as expected, but when trying example.com/foo (trailing slash) it did not redirect to https. – Phil Brown Aug 9 at 21:58
0

First off, my apologies, it appears my question is invalid based on my actual setup (translating urls, names and sections). My ProxyPass* directives were not within a VirtualHost block as the question shows, but were rather applied at a global level in ssl.conf above the default VirtualHost block. By moving the ProxyPass directives into the default VirtualHost block, the http->https redirect now works as expected when the context path matches a ProxyPass path.

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.