using: RewriteRule ^(.+)\.html$ foo.php?qs=$1 Code (markup): If I enter example.html in the browser, $qs in foo.php is echoed "example" But if I change the rule to: RewriteRule ^(.+)\.php$ foo.php?qs=$1 Code (markup): when I enter example.php in the browser, $qs in foo.php is echoed "foo" What is going on? Why isn't $qs in the second example echoing "example"?
Because your killing the original script, which is foo.php aka (.+).php so it gives up and spits out foo.
You can put your code inside the httpd.conf file and use the [L] flag - this will stop the rewrite processing as soon as it's done the first rewrite (X.php to foo.php). As .htaccess files must be interpreted for each request and operate on a per-directory basis, [L] doesn't work quite as expected when used in .htaccess. In that case, you can just add in a rewritecond that checks if it's already on the foo.php script - RewriteCond %{SCRIPT_FILENAME} !foo\.php$ RewriteRule ^(.+)\.php$ foo.php?qs=$1 Code (markup): It depends on how your php scripts work but if they ever need to use the query string, you will want to use the QSA flag otherwise the query string will be overwritten with your qs=filename string.