[Solved]Rewrite not working as expected for static external redirects

Marcus

Well-Known Member
#1
Hi,

I'm trying to do an external rewrite like :

http://example.com/example_url => http://other.server.com/http://example.com/example_url

The rewrite rule I have tried is :

RewriteRule .* http://other.server.com/http://%{SERVER_NAME}%{REQUEST_URI} [R,L]

but this just hangs. The error log shows :

Code:
2010-11-23 13:07:18.104 [INFO] [127.0.0.1:55432-0#proxy-login-redirect] [REWRITE] Rule: Match '/test' with pattern '.*', result: 1
2010-11-23 13:07:18.104 [INFO] [127.0.0.1:55432-0#proxy-login-redirect] [REWRITE] Source URI: '/test' => Result URI: 'http://other.server.com/http://example.com/test'
2010-11-23 13:07:18.104 [INFO] [127.0.0.1:55432-0#proxy-login-redirect] [REWRITE] Last Rule, stop!
I have tried other replacements in the RewriteRule directive which do not work (they just hang, and give similar error log messages to above).

RewriteRule .* http://other.server.com/?u=http://%{SERVER_NAME}%{REQUEST_URI} [R,L]
RewriteRule .* http://other.server.com/http://%{SERVER_NAME}%{REQUEST_URI} [R,L]
RewriteRule .* http://other.server.com%{REQUEST_URI} [R,L]
RewriteRule ^(.*)$ http://other.server.com/u=http://%{SERVER_NAME}$1 [R,L]
RewriteRule ^(.*)$ http://other.server.com/$1 [R,L]

These rules do work though :

RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
RewriteRule .* http://%{SERVER_NAME}:8000%{REQUEST_URI} [R,L]

(where 8000 can be any valid port).

It appears that the problem might be when the redirected server name is statically defined rather than generated at runtime (though I'd need to test more scenarios to confirm that).

Note : these rules are input into the 'Rewrite' section at the virtual host level. I have not tried them in other contexts.

Note also : the error log entries (all log level 9) are identical to the one displayed above (except for the resulting URI), whether the external redirect is successful or not.

Litespeed version : 4.0.17 Standard.

Thanks for looking into this.
 
Last edited by a moderator:

Marcus

Well-Known Member
#5
Yes,

The problem was unrelated to LS - it was because I was testing in a browser, and the page I was trying to redirect to hasn't been created yet. I tried using curl, and it worked as expected.

Sorry to have taken up your time. Thanks for your help.

Marcus.
 
Top