Apache mod_rewrite查询字符串

时间:2014-06-06 12:36:20

标签: php apache mod-rewrite query-string

因此我的staff.php?action=[action]文件会重写为/staff/[action],其中action可以带3个值new/edit/delete

我想在提交时显示成功或失败消息。我尝试重定向到/staff/new&error=[error]/staff/new?error=[error]

但是,var_dump($_GET)仅返回action的查询字符串。

我找到的唯一解决方案是/staff?action=[action]&error=[error],但我不喜欢它。有没有办法改写我的规则?

我不想要/staff/new/error/[error]

## hide .php extension snippet
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L]
# To internally forward /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [L]

RewriteRule ^staff/(.+)$ /staff.php?action=$1 [L]

1 个答案:

答案 0 :(得分:2)

您可以使用 QSA 标志将查询字符串添加到转发的网页

RewriteRule ^staff/(new|edit|delete)$ /staff.php?action=$1 [L,QSA]