Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I'm having loads of trouble trying to integrate proxy, rewrite, and SSL altogether in Apache 2.

A brief history, my application runs on port 8080 and before adding SSL, I used proxy to strip the 8080 from the url's to and from the server.

So instead of www.example.com:8080/myapp, the client app accessed everything via www.example.com/myapp

Here was the conf the accomplished this:

ProxyRequests Off

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

ProxyPass /myapp http://www.example.com:8080/myapp
ProxyPassReverse /myapp http://www.example.com:8080/myapp

What I'm trying to do now is force all requests to myapp to be HTTPS, and then have those SSL requests follow the same proxy rules that strip out the port number as my application used to. Simply changing the ports 8080 to 8443 in the ProxyPass lines does not accomplish this. Unfortunately I'm not an expert in Apache, and my skills of trial and error are already reaching the end of the line.

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule myapp/* https://%{HTTP_HOST}%{REQUEST_URI}

ProxyRequests Off

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

SSLProxyEngine on

ProxyPass /myapp https://www.example.com:8443/mloyalty
ProxyPassReverse /myapp https://www.example.com:8433/mloyalty

As this stands, a request to anything on the server other than /myapp load fine with http. If I make a browser http request to /mypp it then redirects to https:// www.example.com:8443/myapp , which is not the desired behavior. Links within the application then resolve to https:// www.example.com/myapp/linkedPage , which is desirable. Browser requests (http and https) to anything one level beyond just /myapp ie. /myapp/mycontext resolve to https:// www.example.com/myapp/mycontext without the port.

I'm not sure what other information there is for me to give, but I think my goals should be clear.

share|improve this question

1 Answer 1

Your setup is very similar to a VirtualHost I've got here, checking the differences (and the docs) try adding the R flag to your rewrite rule, eg:

RewriteRule ^/(.*) https://%{HTTP_HOST}%{REQUEST_URI} [R]

share|improve this answer
Hmm, wasn't fully aware of the flags. The [R] flag did not seem to accomplish much. The [P] flag created a positive effect in that some forms which broke now work. It seems that once I get to a directory level beyond myapp/ it no longer wants to apply the total set of rewrite and proxy rules –  user58200 Oct 25 '10 at 16:05
I wonder if the problem is related to the rewrite rule not picking up parts of the URI correctly, you could try changing the config around abit to simplify it: (can't paste in code here, try pastebin.com/M6K2J1c2) –  James Yale Oct 27 '10 at 9:30
Hmm, no luck. I had to move some of the Proxy stuff outside the Location because it wasn't allowed, although it did allow the ProxyPasses as long as the context path was removed (since location already handles that I figure). Functionality did not seem to change at all though. Client-side HTTP requests mapped to HTTPS: with the port displayed. Internal application links resolved to HTTP. –  user58200 Oct 27 '10 at 16:20

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.