I have a quite odd mystery. I have a rather simple Apache Rewrite and for some odd reason it is messing up my php Superglobals. First off the Rewrite is as follows:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
When this rule is in place the only Superglobals that are $_GET and $_REQUEST (of course $REQUEST does because it gets them from $_GET, …). No matter what I put in the URL I only ever receive /index_php as the only key and it has no value. At first I thought I had messed something up in my code but as the first line of the index file I tried the following:
foreach($_GET as $key => $value)
{
echo "$key = $value<br/>";
}
foreach($_POST as $key => $value)
{
echo "$key = $value<br/>";
}
foreach($_REQUEST as $key => $value)
{
echo "$key = $value<br/>";
}
The only thing printed is “/index_php = ” twice. I’ve messed with a couple rewrites before but clearly I’m doing something incorrect. As a side note this is my expected behavior:
URL: localhost/users/dashboard?item=id
Which would give me the $_GET superglobal with key: item, value: id. Any help is greatly appreciated.
You need to pass the original query string in your rewrite rule:
That way, regardless of the new values that you might add in the future, the old ones will get passed as well.