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.
我有一组页面,我正在尝试重定向到新的URL。它们在目标URL中具有与原始URL中不同的查询字符串。
http://localhost/people.php?who=a
should redirect to:
应重定向到:
http://localhost/people/?t=leadership
And on and on...
并且......
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]
What's happening is that the first 4 rules don't match and the page redirects to:
发生的事情是前4个规则不匹配,页面重定向到:
http://localhost/people/?who=a
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.
我已经尝试了QSD标志,但似乎我的问题是规则不匹配整个查询字符串,而不是它传递查询字符串。
2 个解决方案
#1
12
You need to match against the %{QUERY_STRING}
variable. The query string isn't part of the match in a RewriteRule
:
您需要匹配%{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]
#2
0
You cannot match QUERY_STRING
in RewruteRule
URI pattern:
您无法在RewruteRule URI模式中匹配QUERY_STRING:
Try your rules like this:
试试这样的规则:
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]
#1
12
You need to match against the %{QUERY_STRING}
variable. The query string isn't part of the match in a RewriteRule
:
您需要匹配%{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]
#2
0
You cannot match QUERY_STRING
in RewruteRule
URI pattern:
您无法在RewruteRule URI模式中匹配QUERY_STRING:
Try your rules like this:
试试这样的规则:
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]