Forum Moderators: phranque
My .htaccess file:
RewriteEngine on
RewriteRule test/([0-9]+) script.php?var=$1
My script.php goes like this:
<?
echo $_GET['var'];
?>
But whenever I run
localhost/test/[any number]
it outputs nothing. It seems that the variable isn't passed at all.
Does someone know what could be wrong here?
Welcome to WebmasterWorld [webmasterworld.com]!
Are you sure the mod_rewrite code is even running? You may need to add
Options +FollowSymLinks
Jim
Edit: Now it works with
localhost/test/[any number]
I removed a comment line before the actual line from the .htaccess file. Does comments in the .htaccess file have any impact on the result?
No, as long as the comment is on a separate line and starts with "#". Comments placed on the same line after a directive will cause Warnings (errors), which will appear in your error log if your error logging level is set to show warnings.
If you want to always access script.php in a fixed location relative to the Web root directory, then you should specify that by prefixing the substitution URL-path with a slash:
RewriteEngine on
RewriteRule test/([0-9]+) [b]/s[/b]cript.php?var=$1 [L]
Refs:
Apache mod_rewrite documentation [httpd.apache.org]
Apache URL Rewriting Guide [httpd.apache.org]
Regular Expressions Tutorial [etext.lib.virginia.edu]
Jim