用查询stringhtaccess RewriteRule页面

我有一组网页,我试图redirect到新的url。 目标url中的查询string与原始url中的查询string不同。

http://localhost/people.php?who=a 

应该redirect到:

 http://localhost/people/?t=leadership 

而且…

我有以下一套重写规则,显然做了一些非常错误的事情。

 RewriteRule ^people.php?who=a /people/?t=leadership [R=301,L] RewriteRule ^people.php?who=f /people/?t=faculty [R=301,L] RewriteRule ^people.php?who=p /people/?t=students [R=301,L] RewriteRule ^people.php?who=r /people/ [R=301,L] RewriteRule ^people.php /people/ [R=301,L] 

发生什么事是前4个规则不匹配,页面redirect到:

 http://localhost/people/?who=a 

我已经尝试了QSD标志,但是看起来像我的问题是规则不匹配整个查询string,而不是它传递查询string。

您需要匹配%{QUERY_STRING}变量。 查询字符串不是RewriteRule匹配的一部分:

 RewriteCond %{QUERY_STRING} ^who=a$ RewriteRule ^people.php$ /people/?t=leadership [R=301,L] RewriteCond %{QUERY_STRING} ^who=f$ RewriteRule ^people.php$ /people/?t=faculty [R=301,L] RewriteCond %{QUERY_STRING} ^who=p$ RewriteRule ^people.php$ /people/?t=students [R=301,L] RewriteCond %{QUERY_STRING} ^who=r$ RewriteRule ^people.php$ /people/ [R=301,L] RewriteCond %{QUERY_STRING} ^$ RewriteRule ^people.php$ /people/ [R=301,L] 

您无法在RewruteRule URI模式中匹配QUERY_STRING

尝试像这样的规则:

 RewriteCond %{THE_REQUEST} \s/+people\.php\?who=a\s [NC] RewriteRule ^ /people/?t=leadership [R=301,L] RewriteCond %{THE_REQUEST} \s/+people\.php\?who=f\s [NC] RewriteRule ^ /people/?t=faculty [R=301,L] RewriteCond %{THE_REQUEST} \s/+people\.php\?who=p\s [NC] RewriteRule ^ /people/?t=students [R=301,L] RewriteCond %{THE_REQUEST} \s/+people\.php(\?who=r)?\s [NC] RewriteRule ^ /people/? [R=301,L]