与查询字符串的htaccess重写规则页面 [英] htaccess RewriteRule page with query string

查看:154
本文介绍了与查询字符串的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]

这篇关于与查询字符串的htaccess重写规则页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆