Rewrite Problem

Discussion in 'General' started by Jetro, Mar 20, 2007.

  1. Jetro

    Jetro New Member

    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
  2. mistwang

    mistwang LiteSpeed Staff

    Can you setup a test server with rewrite logging enabled. This way, we can figure out what causes the loop of redirection.
  3. Jetro

    Jetro New Member

    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.
  4. mistwang

    mistwang LiteSpeed Staff

    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.
  5. Jetro

    Jetro New Member

    But how? I added:
    RewriteOptions MaxRedirects=1

    And there's still problem with infinite loops and internal error 500.
  6. Jetro

    Jetro New Member

    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.
  7. mistwang

    mistwang LiteSpeed Staff

    The leading '/' got choped off for rewrite rules in a .htaccess file, it is called "rewrite base" in Apache. :)

Share This Page