Forum Moderators: phranque

Message Too Old, No Replies

Mod Rewrite Question

Several rewrites taking place

         

ambition

5:27 pm on Jul 3, 2006 (gmt 0)

10+ Year Member



Hello,

I have a site with the following line in the .htaccess file:

RewriteRule ^(.*)add/ $1add_url.php

This basically rewrites /add/1/2/add_url.php to /add/1/2.php.

What I want to do is make all of those /add pages redirect to /add/1/1.php.

So this is what I have so far:

RewriteCond %{REQUEST_FILENAME}!^add/1/1.php
RewriteRule ^(.*)add/([0-9]+)/([0-9]+).php ^add/1/1.php [R=301,L]
RewriteRule ^(.*)add/ $1add_url.php

The condition says don't rewrite it if the request is to add/1/1.php itself, and then rewrite it if it isn't.

For some reason this is still getting thrown into a loop and doesn't resolve to add/1/1.php.

Any ideas? Thanks in advance.

jdMorgan

8:47 pm on Jul 3, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I suspect your REQUEST_FILENAME pattern is never matching, since the pattern is both start-anchored and incomplete. Therefore, it cannot prevent a loop.

I'd suggest you test REQUEST_URI, and include the leading slash in the pattern:


RewriteCond %{REQUEST_URI} [b]!^/a[/b]dd/1/1.php

Also, be aware that a RewriteCond affects only the single RewriteRule that follows it. I don't think that's a problem here, just being thorough...

Jim

ambition

11:47 pm on Jul 3, 2006 (gmt 0)

10+ Year Member



Jim,

This is the second time you have been exactly right with a mod_rewrite issue I was struggling with. That worked perfectly, thanks so much for your help!