Search code examples
apachehttp-redirectproxymod-proxy

Using Apache RedirectMatch in an SSL Vhost


I would like to:

  • redirect https requests for / to /sweetApp/
  • redirect all http requests to https
  • after the redirects, proxy requests to an internal ip address

I have set up these vhost rules. The http to https redirect works but the redirect to /sweetApp/ does not.

In the end, I would like an external request for sweetSite.com to proxy and redirect so the internal server only sees a request for 192.168.3.92:9080/sweetApp/

I am using Apache 2.4.3 so it should support name based ssl vhosts.

#Redirect to SSL
<VirtualHost *:80>
ServerName sweetSite.com
RedirectMatch ^/$ https://sweetSite.com/
</VirtualHost>

# The Real McCoy
<VirtualHost *:443>
ServerName sweetSite.com

#Map to /sweetApp/ by default
RedirectMatch ^/$ /sweetApp/

SSLEngine On
SSLProxyEngine On
SSLCertificateFile ssl/certificate.crt
SSLCertificateKeyFile ssl/certificate.key

#SSL to HTTP Proxy
ProxyPass / http://192.168.3.92:9080/
ProxyPassReverse / http://192.168.3.92:9080/
</VirtualHost>

Solution

  • The problem for me is that if there is a proxyPass rule, it takes precedence over any redirect rule.

    Because I need this machine to do both the redirect and the proxy, the only solution I could find was to use mod_rewrite to "proxy" and to change the url to /sweetApp/.