Rewrite Problem

#1
After upgrading lsws from 2.2.6 to 3.0, one of virtualhosts, that uses rewrite rules in htaccess file, stopped work correctly. :( In server log i see:
ERROR [85.128.x.x:44929-0#hmt.pl] Maximum number of redirect reached.

.htacces:
RewriteEngine On

RewriteCond %{HTTP_HOST} ^endemit\.hmt\.pl [NC]
RewriteRule (.*) /_endemit/$1 [L]
RewriteCond %{HTTP_HOST} ^projekt\.hmt\.pl [NC]
RewriteRule (.*) /_projekt/$1 [L]
RewriteCond %{HTTP_HOST} ^klasad\.hmt\.pl [NC]
RewriteRule (.*) /_klasad/$1 [L]
RewriteCond %{HTTP_HOST} ^www.hmt.pl$
RewriteRule ^(.*)$ http://hmt.pl/ [R=301,L]

ErrorDocument 404 http://hmt.pl/error.php?error=404
ErrorDocument 400 http://hmt.pl/error.php?error=400
ErrorDocument 403 http://hmt.pl/error.php?error=403
ErrorDocument 500 http://hmt.pl/error.php?error=500
 
#3
2007-03-20 18:29:08.186 INFO [xxx:4006-0#hmt.pl] [REWRITE] strip rewrite base: '/' from URI: '/'
2007-03-20 18:29:08.186 INFO [xxx:4006-0#hmt.pl] [REWRITE] Rule: Match '' with pattern '(.*)', result: 2
2007-03-20 18:29:08.186 INFO [xxx:4006-0#hmt.pl] [REWRITE] Cond: Match 'endemit.hmt.pl' with pattern '^endemit\.hmt\.pl', result: 1
2007-03-20 18:29:08.187 INFO [xxx:4006-0#hmt.pl] [REWRITE] Source URI: '' => Result URI: '/_endemit/'
2007-03-20 18:29:08.187 INFO [xxx:4006-0#hmt.pl] [REWRITE] Last Rule, stop!
2007-03-20 18:29:08.187 INFO [xxx:4006-0#hmt.pl] [REWRITE] strip rewrite base: '/' from URI: '/_endemit/'
2007-03-20 18:29:08.187 INFO [xxx:4006-0#hmt.pl] [REWRITE] Rule: Match '_endemit/' with pattern '(.*)', result: 2
2007-03-20 18:29:08.187 INFO [xxx:4006-0#hmt.pl] [REWRITE] Cond: Match 'endemit.hmt.pl' with pattern '^endemit\.hmt\.pl', result: 1
2007-03-20 18:29:08.187 INFO [xxx:4006-0#hmt.pl] [REWRITE] Source URI: '_endemit/' => Result URI: '/_endemit/_endemit/'
2007-03-20 18:29:08.187 INFO [xxx:4006-0#hmt.pl] [REWRITE] Last Rule, stop!
2007-03-20 18:29:08.187 INFO [xxx:4006-0#hmt.pl] [REWRITE] strip rewrite base: '/' from URI: '/_endemit/_endemit/'
2007-03-20 18:29:08.187 INFO [xxx:4006-0#hmt.pl] [REWRITE] Rule: Match '_endemit/_endemit/' with pattern '(.*)', result: 2
2007-03-20 18:29:08.187 INFO [xxx:4006-0#hmt.pl] [REWRITE] Cond: Match 'endemit.hmt.pl' with pattern '^endemit\.hmt\.pl', result: 1
2007-03-20 18:29:08.187 INFO [xxx:4006-0#hmt.pl] [REWRITE] Source URI: '_endemit/_endemit/' => Result URI: '/_endemit/_endemit/_endemit/'

........

2007-03-20 18:29:08.188 INFO [xxx:4006-0#hmt.pl] [REWRITE] strip rewrite base: '/' from URI: '/_endemit/_endemit/_endemit/_endemit/_endemit/_endemit/_endemit/_endemit/_endemit/_endemit/'
2007-03-20 18:29:08.188 INFO [xxx:4006-0#hmt.pl] [REWRITE] Rule: Match '_endemit/_endemit/_endemit/_endemit/_endemit/_endemit/_endemit/_endemit/_endemit/_endemit/' with pattern '(.*)', result: 2
2007-03-20 18:29:08.188 INFO [xxx:4006-0#hmt.pl] [REWRITE] Cond: Match 'endemit.hmt.pl' with pattern '^endemit\.hmt\.pl', result: 1
2007-03-20 18:29:08.188 INFO [xxx:4006-0#hmt.pl] [REWRITE] Source URI: '_endemit/_endemit/_endemit/_endemit/_endemit/_endemit/_endemit/_endemit/_endemit/_endemit/' => Result URI: '/_endemit/_endemit/_endemit/_endemit/_endemit/_endemit/_endemit/_endemit/_endemit/_endemit/_endemit/'
2007-03-20 18:29:08.188 INFO [xxx:4006-0#hmt.pl] [REWRITE] Last Rule, stop!
2007-03-20 18:29:08.188 ERROR [xxx:4006-0#hmt.pl] Maximum number of redirect reached.
 

mistwang

LiteSpeed Staff
#4
There is a subtle change in rewrite engine in release 3.0 that rewritten URL may be processed again.

As you can tell from the log file, the URL has been rewritten again and again by prepending "/_endemit/" repeatedly, you may need to add a rewrite condition to prevent that from happening.
 
#6
Problem solved

RewriteCond %{HTTP_HOST} ^klasad.hmt.pl [NC]
RewriteCond %{CURRENT_URI} !^_klasad
RewriteRule (.*) /_klasad/$1 [L]

But i lost a couple of time, because as You can see at logs in my previous posts, CURRENT_URI don't has "/" at start of the string. I thought that URI always should begin at "/". Correct me if this is this not a bug.
 
Top