Forum Moderators: phranque

Message Too Old, No Replies

Strange PHP-mod_rewrite behavior

Rewritten URL appears in REDIRECT_QUERY_STRING not QUERY string

         

dnellis74

6:48 pm on Oct 21, 2004 (gmt 0)

10+ Year Member



Greetings,

Searching this forum I found great help to generating rewrite rules to make a dynamic request appear search engine friendly URLs aka?cat1=foo&cat2=bar /foo/bar.

Now my php is being ornery.

Here are my rewrite rules. This is inside of a directory directive:

RewriteRule ^([^/]+)/([^/]+) index.php?state=$1&city=$2 [L]
RewriteRule ^([^/]+) index.php?state=$1 [L]

Now after accessing somehting like [mysite.com...] in PHP when I print out the $_SERVER variable I get two interesting bits of output:

[REDIRECT_QUERY_STRING] => state=AK
[QUERY_STRING] => state=index.php

How on Earth did state get assigned to be index.php? Its not in the original query at all. Do you think some other directive higher up in the site is fiddling with things? I think REDRIECT_QUERY_STRING is an apache cariable. Did apache work correctly and PHP is goofing up.

Thanks in advance if you can straighten me out

jdMorgan

7:58 pm on Oct 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



dnellis,

Welcome to WebmasterWorld!

Try adding a RewriteCond to each rule:


RewriteCond %{REQUEST_URI} !^index\.php

This will prevent recursion, which may be the cause of your problem.

Jim

dnellis74

9:56 pm on Oct 21, 2004 (gmt 0)

10+ Year Member



Jim,

Thanks for your quick reply.

Evidentally recursion is not the issue. Adding the condition you suggested didnt help.

I've cross posted in PHP. Hopefully someone there will have an idea of whats up.....

Dave

dnellis74

11:16 pm on Oct 21, 2004 (gmt 0)

10+ Year Member



This problem is definately Apache related.

Just for grins, I changed my rewrite rules to read:

RewriteRule ^([^/]{2})/([^/]{3,}) index.php?state=$1&city=$2 [L]
RewriteRule ^([^/]{2}) index.php?state=$1 [L]

And the second rule started working! I was very excited at this point! As I started poking around the interface, and checking out Colorado, the only place data is actually entered, I witnessed the following:

[REDIRECT_QUERY_STRING] => state=CO
[REDIRECT_URL] => /secure/flowers/CO
[QUERY_STRING] => state=in

At some point I clicked on the link to Indiana, and now the query string will *not* change. I've even restarted apache.

What is going on?