I just wrote a htaccess file and a simple rule.
RewriteRule ^/?([a-z]{2})/([0-9]{4})/?$ /run/run.php?country=$1&year=$2 [NC,L]
This does http://www.localhost/us/2014
On the php page, I accidently did:
echo $country.' '.$year;
This gave me the output below, which is correct.
us 2014
I did not do:
$country = $_GET['country'];
$year = $_GET['year'];
But it still worked. Is this normal behaviour. Can I use this for the rest of the rules and the site? I'm using WAMP on Windows 7 Home Premium.
You might have turned on register_globals
in php.ini. Thats why you are getting variable with the name of array index (Here $_GET
). It is not a best practice to turn on register_globals
.
You can read more here, why register_globals is bad.
In my opinion this has nothing common with .htaccess. What PHP gets is the second part of ReWrite rule, so $_GET
variables should be accessible. The server gets http://www.localhost/us/2014
and the PHP gets /run/run.php?country=us&year=2014
As nauphal wrote this might be (probably is) the register_globals issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With