Forum Moderators: phranque

Message Too Old, No Replies

Rewrite with ProxyPass in case of SSL

Can Rewrite be used along with Proxypass?

         

Gilraen

6:55 am on Feb 18, 2009 (gmt 0)

10+ Year Member



Hey,

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]

Gilraen

1:41 pm on Feb 18, 2009 (gmt 0)

10+ Year Member



Hey,

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]

jdMorgan

5:42 pm on Feb 18, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Your "day" may be 8 to 16 hours different than the contributors' "day" here. Also, there are many "askers" and few contributors, so please be patient. This is not instant messaging.

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]

Gilraen

7:50 am on Feb 19, 2009 (gmt 0)

10+ Year Member



Hey Jim,

Thank you so much for the reply. Sorry for being impatient.. was at my wit's end..

Will try your suggestion asap and let u know, can u also help with my first problem, please?

Regards,
Roshini

jdMorgan

3:16 pm on Feb 19, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I intend to help, but simplify first, then add complexity in small increments to avoid a debugging nightmare.

Jim

Gilraen

10:32 am on Feb 20, 2009 (gmt 0)

10+ Year Member



Ok here's how things stand:

I can redirect from http://www.example.com/ to http://www.example.com/abc/ easily with a simple rewrite statement. But the procedure does not work with https.

Why so?

jdMorgan

8:29 pm on Feb 20, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Please give us something to work with here. What does the relevant code look like now?

Jim

Gilraen

9:44 am on Feb 23, 2009 (gmt 0)

10+ Year Member



This part was supposed to rewrite [example.com...] to [example.com...]

RewriteEngine on
RewriteCond %{REQUEST_URI} !^/abc/(.*)$
RewriteRule ^/(.*)$ [example.com...] [R,L]

But it doesn't work.

jdMorgan

5:04 pm on Feb 23, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Do you have Options FollowSymLinks or SymLinksIfOwnerMatch set in this context? One or the other is required to enable mod_rewrite.

Anything in your server error log?

What happens if you simplify that rule to an unconditional redirect to google.com, and test that?

Jim

Gilraen

7:32 am on Feb 24, 2009 (gmt 0)

10+ Year Member



i think my rewrite is working fine.. initially i had used the same code to redirect from http://www.example.com/ to http://www.example.com/abc/. That had worked.

Note: I want the same for httpS.