mod_rewrite可以导致GET请求被忽略吗?

时间:2013-04-08 09:49:02

标签: php .htaccess mod-rewrite get

我无法访问我的获取请求...

我的.htaccess:

Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /alex
RewriteRule ^admin/([a-zA-Z0-9]+)/?$ admin/index.php?page=$1
RewriteRule ^admin/([a-zA-Z0-9]+)?$ admin/index.php?page=$1
RewriteCond %{REQUEST_URI}  !(admin|assets|inventory|test)
RewriteRule ^([a-zA-Z0-9]+)/$ index.php?page=$1
RewriteCond %{REQUEST_URI}  !(admin|assets|inventory|test)
RewriteRule ^([a-zA-Z0-9]+)$ index.php?page=$1
ErrorDocument 404 /alex/index.php?page=404
ErrorDocument 403 /alex/index.php?page=404

我正在点击的网址:

  

http://example.com/alex/admin/users?pagenum=37

示例PHP代码:

echo $_GET["pagenum"];

但是,我的php完全没有得到变量回声。我的.htaccess导致这个吗?如果不是......是什么?

1 个答案:

答案 0 :(得分:4)

您需要在重写中使用QSA标记:

Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /alex
RewriteRule ^admin/([a-zA-Z0-9]+)/?$ admin/index.php?page=$1 [L,QSA]
RewriteRule ^admin/([a-zA-Z0-9]+)?$ admin/index.php?page=$1 [L,QSA]
RewriteCond %{REQUEST_URI}  !(admin|assets|inventory|test)
RewriteRule ^([a-zA-Z0-9]+)/$ index.php?page=$1 [L,QSA]
RewriteCond %{REQUEST_URI}  !(admin|assets|inventory|test)
RewriteRule ^([a-zA-Z0-9]+)$ index.php?page=$1 [L,QSA]

该标志会将任何现有的查询字符串附加到您在规则目标中构建的查询字符串的末尾。通常,如果规则的目标中没有?,则默认情况下会附加查询字符串。但是,如果目标中有?,则需要QSA