Forum Moderators: phranque
ProxyPass /abc/ http://www.example.com:8181/abc/
ProxyPassReverse /abc/ http://www.example.com:8181/abc/
<VirtualHost *:443>
SSLProxyEngine On
ProxyPass [example.com:443...] [example.com:8443...]
ProxyPassReverse [example.com:443...] [example.com:8443...]
</VirtualHost>
<VirtualHost *:80>
RewriteEngine on
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^.*$ [%{SERVER_NAME}%{REQUEST_URI}...] [L,R]
</VirtualHost>
I'm using the above piece of code to redirect from http to https. Also, I'm using proxypass to redirect from port 443 to port 8443. (My Apache web server is on port 443 while my tomcat[which has my application] is on port 8443). All this works fine if i enter [example.com...] or http://www.example.com/abc/ in my url. The problem is that I also want [example.com...] or http://www.example.com/ to redirect to [example.com...] (I think this is called internal rewrite?). For this, I changed the above code to look like this:
ProxyPass /abc/ http://www.example.com:8181/abc/
ProxyPassReverse /abc/ http://www.example.com:8181/abc/
<VirtualHost *:443>
/**added this**/
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/abc/(.*)$
RewriteRule ^/(.*)$ [example.com...] [R,L]
/**end**/
SSLProxyEngine On
ProxyPass [example.com:443...] [example.com:8443...]
ProxyPassReverse [example.com:443...] [example.com:8443...]
</VirtualHost>
<VirtualHost *:80>
RewriteEngine on
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^.*$ [%{SERVER_NAME}%{REQUEST_URI}...] [L,R]
</VirtualHost>
This does not work. If i enter [example.com...] in my browser url, then it goes to default Tomcat home page! The same procedure (Rewrite + proxypass) works fine when I am only dealing with non-ssl (http). Can anyone see what's wrong with above code.
[edited by: Gilraen at 7:02 am (utc) on Feb. 18, 2009]
[edited by: jdMorgan at 5:35 pm (utc) on Feb. 18, 2009]
[edit reason] example.com [/edit]
I have been working on this all day..
Please do help!
One more issue I just noticed in this:
If i enter "http://www.example.com/abc" without any trailing slash, then it doesn't redirect properly.
Any Ideas?
[edited by: jdMorgan at 5:35 pm (utc) on Feb. 18, 2009]
[edit reason] example.com [/edit]
Two comments:
There is no need to check the %{SERVER_PORT} in a <VirtualHost> container which is already qualified by a port number.
Your missing trailing slash URL doesn't work because your pattern requires that trailing slash. Modify the pattern to make that slash optional, or detect and redirect slashless requests to add the slash -- This latter method also prevents duplicate-content problems (the same content at two or more different URLs).
Jim
[edited by: jdMorgan at 2:12 am (utc) on Feb. 19, 2009]
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/abc/(.*)$
RewriteRule ^/(.*)$ [example.com...] [R,L]
But it doesn't work.