Forum Moderators: phranque

Message Too Old, No Replies

mod rewrite problem

         

isitreal

8:06 pm on Jul 26, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Can someone figure this one out, it's beyond me:

I'm trying to rewrite /folder1/folder2/greg.php to /folder1/folder2/fred.php, then place 'greg.php' into the query string for fred.php

RewriteEngine On
RewriteBase /folder1/folder2/
RewriteRule ^(.*)$ fred.php?page=$1 [L]

This correctly rewrites to fred.php, but then insists on placing fred.php, instead of greg.php, into page=$1.

This is doing it on both my development server and the hosting server, so I'm pretty sure there's no configuration problems. I also have several other sites running mod_rewrite without any problem on both servers.

the query string is used to write out the content of fred.php, but of course that's failing.

jdMorgan

8:15 pm on Jul 26, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Looks like you've created a loop. Try adding a RewriteCond exclusion:

RewriteCond %{REQUEST_URI} !fred\.php$

Jim

isitreal

8:23 pm on Jul 26, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Jd, that worked, you're a genius at this stuff, thanks a million, I was trying to figure this out for myself for the last too many hours, but I don't understand how a loop like this could happen, I've used almost identical syntax before.

I thought that when you do a rewrite you are telling mod_rewrite:

take what is in (.*), put it into the $1, then rewrite using that value. Obviously I'm missing something there conceptually about how mod_rewrite works.

<added>
so this is what ended up working:
RewriteEngine On
RewriteBase /folder1/folder2/
RewriteCond %{REQUEST_URI}!fred\.php$
RewriteRule ^(.+)$ fred.php?page=$1 [L]

[edited by: isitreal at 8:28 pm (utc) on July 26, 2004]

jdMorgan

8:27 pm on Jul 26, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, but any further file lookup or checking that occurs for *this HTTP request* may cause your .htaccess to be re-processed (I don't know why, but it happens). So, the first rewrite worked correctly, but then it was run again, and put "fred' into the query string.

Jim

isitreal

8:29 pm on Jul 26, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Again, thanks, if you don't know why it happens, I'll just accept that it happens, I was about to put my head through the wall on this one.