Trying to setup .htaccess so I can redirect a url like http://example.com/io/abc123 to http://example.com/io/io.php?id=abc123.
But, for some reason, the RewriteRule does not work as I expect.
I want to keep this redirection local without messing up the root .htaccess file, and so I create a new .htaccess file inside the io subdirectory. (Doing the equivalent in the root directory gives the same outcome, so it's not that).
Directory structure:
www
|
+--io
|
+-- .htaccess
\-- io.php
.htaccess file:
RewriteEngine on
RewriteRule ^(.*)$ io.php?id=$1
io.php file:
<?php
echo "Hello World" . "\n";
echo "REQUEST_URI=[" . $_SERVER['REQUEST_URI'] . "]\n";
echo "PHP_SELF=[" . $_SERVER['PHP_SELF'] . "]\n";
echo "QUERY_STRING=[" . $_SERVER['QUERY_STRING'] . "]\n";
$id = $_GET['id'];
echo "id='" . $id . "'\n";
?>
OUTPUT
Hello World
REQUEST_URI=[/io/abc123]
PHP_SELF=[/io/io.php]
QUERY_STRING=[id=io.php]
id='io.php'
For reasons I don't understand, instead of the expected query_string id=abc123 this results in id=io.php.
It's obviously getting the rewrite correct to the target file io.php, but fails to substitute the abc123 into the id parameter using $1.
What am I doing wrong?