301 redirect looping with mod_rewrite

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,

I am trying to use mod_rewrite (apache 2) to give my website pretty
URLs, but for some reason I get stuck in a 301 redirect loop. I have
looked at the code over and over again. I know what lines cause the loop
but I can't find out why it's looping. There's probably something wrong
with my understanding of mod_rewrite. Anyway, here are the rules I use
(numbered for ease):

This bit takes an old, ugly URL and redirects to a new, pretty URL with
a 301. In my understanding the l stops mod_rewrite and the browser
simply sends out a new request for the new URL. Example:
index.php?t=somepage becomes /page/somepage/

(1) RewriteCond %{query_string} t=([a-z]+)
(2) RewriteRule ^index.php$ /page/%1/? [r=301,l]

The next rule makes sure that the pretty URLs all end in a slash. It
also does a 301 redirect causing the browser to send a new request.

(3) RewriteRule ^page/([^/]+)$ /page/$1/ [r=301,l]

Here I parse the new pretty URL to get the old URL back for processing.

(4) RewriteRule ^page/([^/]+)/$ /index.php?t=$1

Rule 1 and 2 work. I get the pretty URL in my address bar. Rule 3 and 4
also work, but only if I comment out rule 1 and 2. If all 4 rules are
active I get 301 redirects on the new pretty URL. It doesn't matter if
the pretty URL came from rule 1 and 2 or if I manually type a pretty URL
in the address bar.

The thing I don't get: Why would rule 1 and 2 affect a pretty URL? It
doesn't match! Only rule 4 should match a pretty URL, and when rule 4
turns the pretty URL back into an old URL, the rewriting is done.

Unless I completely misunderstand mod_rewrite and for some reason the
rules are parsed *again* after rule 4 has been applied...

Any help would be greatly appreciated. Kind regards,

-- 
Sander Marechal

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@xxxxxxxxxxxxxxxx
   "   from the digest: users-digest-unsubscribe@xxxxxxxxxxxxxxxx
For additional commands, e-mail: users-help@xxxxxxxxxxxxxxxx


[Index of Archives]     [Open SSH Users]     [Linux ACPI]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Squid]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux