Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.htaccess: GET variables are lost in rewrite

Tags:

Apparently, my .htaccess rewrite eats up all $_GET-variables on my page:

When accessing the URL http://192.168.1.1/welcome/test?getvar=true and running var_dump($_GET) in my index.php file, I get this this output:

array '/welcome/test' => string '' (length=0) 

So no $_GET-data available and no sign of the getvar-variable from my URL.

Here's my .htaccess:

RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?/$1 [L] 

What should I change to ensure that my rewrite is working as intended but $_GET-variables still are accessible?

like image 647
Industrial Avatar asked Jul 11 '11 20:07

Industrial


2 Answers

You need the "QueryString Append" option:

RewriteRule ^(.*)$ index.php?route=/$1 [QSA,L]

Edit: Added @DonSeba's contribution, because it is correct.

like image 78
Kevin Stricker Avatar answered Jan 04 '23 01:01

Kevin Stricker


minor detail change :

RewriteRule ^(.*)$ index.php?/$1 [L] 

to

RewriteRule ^(.*)$ index.php?route=$1 [QSA,L] 

now all routes will be visible in $_GET["route"]

like image 40
DonSeba Avatar answered Jan 04 '23 00:01

DonSeba