Forum Moderators: phranque
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]
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]
Does this help?
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]
Jim