Re: 301 redirect looping with mod_rewrite

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

 



On 5/17/07, Sander Marechal <s.marechal@xxxxxxxxx> wrote:

(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

Are you forced to use .htaccess for this? If not, you should put this
stuff in the main server context of httpd.conf. It makes things much
easier, and also gives you access to the RewriteLog, which is the only
reasonable way to debug mod_rewrite problems.

Your problem is that the results of (4) are getting reinjected to
mod_rewrite for processing, and will then obviously match (1) and (2).
Since I don't use mod_rewrite in .htaccess, I can't tell you exactly
how to fix this, but here are a few ideas:

1. Instead of rewriteing to /index.php, rewrite to the complete
filesystem path (eg. /usr/local/apache2/htdocs/index.php).

2. On rule (2) include the [NS] flag.

3. If all else fails, simply rename index.php to index-new.php. Nobody
from the outside world should care about this, since this name is
never used externally. But it will avoid the loop.

Joshua.

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