I'm attempting to use PHP mod_rewrite to change some Web addresses.

Like a test, during my .htaccess I've the next:

RewriteEngine on
RewriteRule ^(.*[^/])$ index.php?test=$1
#RewriteRule ^([^/]+)/$ index.php?test=$1

During my index.php file I've simply

<?php print_r($_GET) ?>

What I must happen is the fact that when either mysite.com/test or mysite.com/test/ is incorporated in the browser address bar, the PHP $_GET['test'] variable has got the value 'test' inside it.

The said line works fine with mysite.com/test/ but appears to complete nothing with mysite.com/test

The 2nd line (the uncommented one) produces a worth of 'index.php' for $_GET['test'] when viewing mysite.com/make sure does not so something with mysite.com/test/

Can there be anything I am looking over here that will permit me to obtain the preferred results?


Do this:

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*?)/?$ index.php?test=$1

Note for *? quantifier, which declares * to become ungreedy