Forum Moderators: coopster
Searching this forum I found great help to generating rewrite rules to make a dynamic request appear as static search engine friendly URLs. For example :?cat1=foo&cat2 => bar /foo/bar.
My php seems like its 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 in QUERY_STRING? 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 variable. Did apache work correctly and PHP is goofing up?
Thanks in advance if you can straighten me out. I am pretty stumped.
I made a small bit of progress on this since I posted, and I'm pretty sure that is this an Apache issue and not a PHP issue.
When I print_r $_SERVER I get two interesting bits output:
[REDIRECT_QUERY_STRING] => state=AK
[QUERY_STRING] => state=index.php
So the redirect string is correct, and the query string is pretty bizarre. This is definately a question for an Apache expert, but maybe a PHP person will be able to shed some light. Not to mention they are all Apache experts too :)
RewriteRule ^([^/]+)/([^/]+) index.php?state=$1&city=$2 [L]
RewriteRule ^([^/]+) index.php?state=$1 [L]
It looks like it's not stopping at the [L] flag when it has a match (also, your regex doesn't match correctly as you'll see). So you seem to be having something like this happening...
directory/AK (this matches the first rule and yields:)
=>index.php?state=directory&city=AK (this matches the second rule and yields:)
=>index.php?state=index.php?state=directory&city=AK (the second? and after gets thrown away:)
=>index.php?state=index.php
Try putting this in as your first rewrite rule
RewriteRule ^(.*)index.php(.)$ - [L]
As for the other rule, you need something that takes into account the "directory" term and throws it away or uses it somehow.