Reputation: 343
I would like to force my users to use https to log in. Unfortunately the "redirect" directive does not seem to work in cunjunction with "ProxyPass"
<VirtualHost *:80>
ServerName www.domain.com
# This does not work
Redirect permanent /app/login.jsp https://www.domain.com/app/login.jsp
ProxyPass /app http://localhost:8080/app
ProxyPassReverse /app http://localhost:8080/app
</VirtualHost>
Any idea ? Thanks.
Upvotes: 16
Views: 40840
Reputation: 20882
I had a more complicated use case and it required the use of ProxyPassMatch
. It went a little something like this:
ProxyPassMatch ^/app(/(index.html)?)?$ !
RedirectMatch ^/app(/(index.html)?)?$ /path/to/login/page.html
ProxyPass /app/* http://remote-server/app
ProxyPassReverse /app/* http://remote-server/app
I had to use ProxyPassMatch
because ProxyPass
otherwise performs prefix-matching. You need to match on the end-of-string, so ProxyPassMatch
with a $
regular expression metacharacter is critical.
Here, RedirectMatch
is used in the same way, because Redirect
also performs prefix-matching as well. The two directives also have a nice symmetry, too.
Upvotes: 7
Reputation: 145
Found an answer to this question here:
https://serverfault.com/questions/605931/can-you-use-redirect-and-proxypass-at-the-same-time
The following needs to be added before the other proxypass directives:
ProxyPass /app/login.jsp !
Upvotes: 13
Reputation: 22881
As you identified, the fact you have a ProxyPass
for location /app
means anything hitting that path will be subject to the proxy.
You could omit using ProxyPass
and do the proxy with a RewriteRule
and the proxy [P]
flag:
<VirtualHost *:80>
ServerName www.domain.com
RewriteRule ^/(app/login.jsp)$ https://www.domain.com/$1 [R=301,L]
RewriteRule ^/app(.*) http://localhost:8080/app$1 [P]
ProxyPassReverse /app http://localhost:8080/app
</VirtualHost>
Upvotes: 1