.htaccess:GET变量在重写时丢失

Ind*_*ial 19 php .htaccess mod-rewrite apache2

显然,我的.htaccess重写会占用$_GET我页面上的所有变量:

当访问URL http://192.168.1.1/welcome/test?getvar=truevar_dump($_GET)在我的index.php文件中运行时,我得到了这个输出:

array
'/welcome/test' => string '' (length=0)
Run Code Online (Sandbox Code Playgroud)

所以没有 - $_GET数据可用,并且没有getvar来自我的URL 的变量的迹象.

这是我的.htaccess:

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

我应该更改什么以确保我的重写按预期工作但$_GET变量仍可访问?

Kev*_*ker 60

您需要"QueryString Append"选项:

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

编辑:添加了@ DonSeba的贡献,因为它是正确的.


Don*_*eba 8

细微变化:

RewriteRule ^(.*)$ index.php?/$1 [L]
Run Code Online (Sandbox Code Playgroud)

RewriteRule ^(.*)$ index.php?route=$1 [QSA,L]
Run Code Online (Sandbox Code Playgroud)

现在所有路线都在$ _GET ["route"]中可见