与查询字符串的htaccess重写规则页面
我有一组我试图重定向到新网址的网页。他们在目标URL不同的查询字符串比原来的URL。
I have a set of pages that I'm trying to redirect to new URLs. They have different query strings in the target URL than in the original URL.
http://localhost/people.php?who=a
应该重定向到:
http://localhost/people/?t=leadership
和和...
我有下面的一组重写规则和我显然做一些非常错误的。
I have the following set of rewrite rules and am obviously doing something very wrong.
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规则不匹配和页面重定向到:
What's happening is that the first 4 rules don't match and the page redirects to:
http://localhost/people/?who=a
我已经试过了QSD标志,但似乎我的问题是,规则不匹配的整个查询字符串,而不是它的沿传递查询字符串。
I have tried the QSD flag, but it seems like my problem is that the rule isn't matching on the entire query string, not that it's passing the query string along.
您需要匹配对%{QUERY_STRING}
变量。查询字符串是不是在比赛一重写规则
的一部分:
You need to match against the %{QUERY_STRING}
variable. The query string isn't part of the match in a 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]