如何阻止.htaccess剥离查询字符串?

时间:2013-04-30 23:49:13

标签: .htaccess codeigniter

我有一个.htacces fil(用于codeigniter),所以我不需要包含index.php文件名:

RewriteEngine on
RewriteCond $1 !^(index\.php|assets|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

这可以按预期工作:

http://domain.com/controller/method变为http://domain.com/index.php/controller/method

但是,这不是故意的:

http://domain.com/controller/method/?option=yes变为http://domain.com/index.php/controller/method

我如何保留查询字符串?

1 个答案:

答案 0 :(得分:2)

RewriteRule

中设置QSA(查询字符串追加)标记
RewriteRule ^(.*)$ /index.php/$1 [L,QSA]

来自documentation

  

当替换URI包含查询字符串时,RewriteRule的默认行为是丢弃现有查询字符串,并将其替换为新生成的查询字符串。使用[QSA]标志会导致组合查询字符串。

相关问题