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 to redirect to when "ProxyPass /foo" is also present.
I have followed the advice here, which is quite standard based on googling:
So I basically have:
<VirtualHost *:80> ServerName Redirect /
</VirtualHost>
<VirtualHost *:443> ServerName # ... SSL configuration here ... ProxyPass /foo ProxyPassReverse /foo
</VirtualHost>However, the redirect from http to https seems to only work if there is no matching ProxyPass path. For example:
=> =>
The following Rewrite rules work, but Apache recommends against using Rewrite:
RewriteCond %{HTTPS} !=on
RewriteRule "^/?(.*)" [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?
22 Answers
Try the same config but with a Location parameter to break out your ProxyPass config
<VirtualHost *:443> ServerName # ... SSL configuration here ... <Location "/foo/"> ProxyPass ProxyPassReverse </Location>
</VirtualHost> 1 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.