john doe john doe - 3 months ago 14
PHP Question

Mod rewrite put entire REQUEST_URI into GET request

I am trying to pass the entire Request_Uri into a $_GET request however the only things it's passing is 'test.php'

Htaccess code
RewriteEngine on
RewriteRule ^(.*)$ test.php?data=$1 [L]

test.php
<?php
echo $_GET['data'];
?>


However the only thing it display is 'test.php' what am I doing wrong?

Answer

Use this:

RewriteEngine on

# skips files
RewriteCond %{REQUEST_FILENAME} !-f
# skips directories
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ test.php?data=$1 [L,QSA]

Without these 2 conditions your rules runs twice since you're matching .* and you get rewritten URI test.php as GET parameter.