Forum Moderators: phranque

Message Too Old, No Replies

apache.mod_rewite, while falgs[L] set but dead-loop met?

mod_rewrite,rewriterule

         

zcoral

6:03 am on Apr 7, 2005 (gmt 0)

10+ Year Member



setting in the .htaccess

RewriteEngine On
RewriteRule ^b\.html$ a.html [L]
RewriteRule ^a\.html$ b.html [L]

but got in dead-loop forever unless httpd stop.
the rewrite.log logged called eachother interval:

192.168.0.11 - - [07/Apr/2005:13:15:47 --0400] [home.example.net.nl/sid#8145548][rid#81c3498/initial] (1) [per-dir /usr/local/apache/htdocs/app/] internal redirect with /b.html [INTERNAL REDIRECT]
192.168.0.11 - - [07/Apr/2005:13:15:47 --0400] [home.example.net.nl/sid#8145548][rid#81caef8/initial/redir#1] (1) [per-dir /usr/local/apache/htdocs/app/] internal redirect with /a.html [INTERNAL REDIRECT]
192.168.0.11 - - [07/Apr/2005:13:15:47 --0400] [home.example.net.nl/sid#8145548][rid#81cb750/initial/redir#2] (1) [per-dir /usr/local/apache/htdocs/app/] internal redirect with /b.html [INTERNAL REDIRECT]
192.168.0.11 - - [07/Apr/2005:13:15:47 --0400] [home.example.net.nl/sid#8145548][rid#81cc650/initial/redir#3] (1) [per-dir /usr/local/apache/htdocs/app/] internal redirect with /a.html [INTERNAL REDIRECT]
192.168.0.11 - - [07/Apr/2005:13:15:47 --0400] [home.example.net.nl/sid#8145548][rid#81cd488/initial/redir#4] (1) [per-dir /usr/local/apache/htdocs/app/] internal redirect with /b.html [INTERNAL REDIRECT]
192.168.0.11 - - [07/Apr/2005:13:15:47 --0400] [home.example.net.nl/sid#8145548][rid#81ce438/initial/redir#5] (1) [per-dir /usr/local/apache/htdocs/app/] internal redirect with /a.html [INTERNAL REDIRECT]
192.168.0.11 - - [07/Apr/2005:13:15:47 --0400] [home.example.net.nl/sid#8145548][rid#81cf228/initial/redir#6] (1) [per-dir /usr/local/apache/htdocs/app/] internal redirect with /b.html [INTERNAL REDIRECT]
192.168.0.11 - - [07/Apr/2005:13:15:47 --0400] [home.example.net.nl/sid#8145548][rid#81d0370/initial/redir#7] (1) [per-dir /usr/local/apache/htdocs/app/] internal redirect with /a.html [INTERNAL REDIRECT]
192.168.0.11 - - [07/Apr/2005:13:15:47 --0400] [home.example.net.nl/sid#8145548][rid#81d1278/initial/redir#8] (1) [per-dir /usr/local/apache/htdocs/app/] internal redirect with /b.html [INTERNAL REDIRECT]
192.168.0.11 - - [07/Apr/2005:13:15:47 --0400] [home.example.net.nl/sid#8145548][rid#81d24b8/initial/redir#9] (1) [per-dir /usr/local/apache/htdocs/app/] internal redirect with /a.html [INTERNAL REDIRECT]
192.168.0.11 - - [07/Apr/2005:13:15:47 --0400] [home.example.net.nl/sid#8145548][rid#81d3510/initial/redir#10] (1) [per-dir /usr/local/apache/htdocs/app/] internal redirect with /b.html [INTERNAL REDIRECT]
192.168.0.11 - - [07/Apr/2005:13:15:47 --0400] [home.example.net.nl/sid#8145548][rid#81d4878/initial/redir#11] (1) [per-dir /usr/local/apache/htdocs/app/] internal redirect with /a.html [INTERNAL REDIRECT]
192.168.0.11 - - [07/Apr/2005:13:15:47 --0400] [home.example.net.nl/sid#8145548][rid#81d5ad8/initial/redir#12] (1) [per-dir /usr/local/apache/htdocs/app/] internal redirect with /b.html [INTERNAL REDIRECT]
192.168.0.11 - - [07/Apr/2005:13:15:47 --0400] [home.example.net.nl/sid#8145548][rid#81d7010/initial/redir#13] (1) [per-dir /usr/local/apache/htdocs/app/] internal redirect with /a.html [INTERNAL REDIRECT]
192.168.0.11 - - [07/Apr/2005:13:15:47 --0400] [home.example.net.nl/sid#8145548][rid#81d8778/initial/redir#14] (1) [per-dir /usr/local/apache/htdocs/app/] internal redirect with /b.html [INTERNAL REDIRECT]

what is my wrong, isn't [L] means the last one to match, then quick out of this request?

Frederick

[edited by: jdMorgan at 1:50 pm (utc) on April 7, 2005]
[edit reason] Removed specific domain per TOS. [/edit]

zcoral

9:07 am on Apr 7, 2005 (gmt 0)

10+ Year Member



what it is mean, one reply lost?

sitz

9:28 am on Apr 7, 2005 (gmt 0)

10+ Year Member



[L] *does* mean 'last Rule', but that only applies to the current request. Once the request has been rewritten, the rewritten version is sent back through the rule chain again (it is, after all, a new request at that point). =)

Make sense?

zcoral

9:56 am on Apr 7, 2005 (gmt 0)

10+ Year Member



your means the once the upper Rule match, it will be one brandnew request, so it always found it match one?

then is it said that infact impossible to avoid the dead-loop by some flags say "hello,welldone, turn home"?

thanks in advance
frederick

sitz

10:13 am on Apr 7, 2005 (gmt 0)

10+ Year Member



In this particular case, it is impossible to prevent an infinite loop simply by using flags. That is not to say that it's impossible prevent the loop from occurring:

RewriteEngine on
RewriteCond %{QUERY_STRING}!^r=1$
RewriteRule ^a.html /b.html?r=1 [L]
RewriteCond %{QUERY_STRING}!^r=1$
RewriteRule ^b.html /a.html?r=1 [L]

Tack on a little query string, and only redirect if it's not there. Since the redirect is internal, the end-user never sees the query string snippet at all. Note that if the original URL already contains a query string, you may have to tweak it thusly:


RewriteEngine on
RewriteCond %{QUERY_STRING}!^r=1
RewriteRule ^a.html /b.html?r=1 [L,QSA]
RewriteCond %{QUERY_STRING}!^r=1
RewriteRule ^b.html /a.html?r=1 [L,QSA]

For information on the QSA flag, see [httpd.apache.org ]

Does this help?

zcoral

1:35 pm on Apr 7, 2005 (gmt 0)

10+ Year Member



thanks SITZ, u help me a lot

frederick

jdMorgan

1:51 pm on Apr 7, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Frederick,

Welcome to WebmasterWorld!

The following code demonstrates a method to avoid internal rewrite deadloops by using the server variable "THE_REQUEST."


RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /b\.html\ HTTP
RewriteRule ^b\.html$ /a.html [L]
#
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /a\.html\ HTTP
RewriteRule ^a\.html$ /b.html [L]

To avoid the problem you reported in your other thread, always flush your browser cache (Temprorary Internet Files) before testing any changes to your access-control code. If you change httpd.conf, you also must restart your server.

Jim

sitz

3:25 am on Apr 8, 2005 (gmt 0)

10+ Year Member



*files that one away in the old bag-o-tricks*

=)