通过查询字符串使用重写规则 [英] Use rewrite rule by query string

查看:123
本文介绍了通过查询字符串使用重写规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎么能作出这样的,如果 QUERY_STRING 相匹配的东西,将使用规则?

How can I make that if the QUERY_STRING matches something it would use that rule?

Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /

RewriteRule ^(.*)/?$ index.php?uri=$1 [L,QSA]

RewriteCond %{QUERY_STRING} uri=admin
ReqriteRule ^admin\?(.*)/?$ index.php?uri=admin&q=$1 [L,QSA]

例如。 的http://本地主机/管理调查/新 应该是paramater ,该查询会的uri =管理及放?; Q =轮询/新

Eg. http://localhost/admin?poll/new After the ? should be the paramater q, the the query would be uri=admin&q=poll/new

我如何能做到这一点任何想法?

Any idea on how I could do this?

感谢。

推荐答案

好了,它发生,你的问题是不是我给你,你不希望在查询字符串内容的任何分析的链接更简单。

Well, it happens that your problem is more simple than the link I gave you as you do not want any analysis on the query string content.

如果你用这个单行:

RewriteRule ^admin index.php?uri=admin&q= [L,QSA]

在哪里QSA平均追加查询字符串的结果。您将获得一个内部重定向到:

Where QSA mean append the query string to the result. You will obtain an internal redirection to:

index.php?uri=admin&q=&poll/new

这也不行,这是因为你用参数的方式(管理​​?调查/新)是不标准的方式。如此看来,我们需要捕捉查询字符串的内容并把它放在手放在重写规则。这应该工作(如果你需要它仅适用于/管理URL):

Which is not OK, this is because the way you use argument (admin?poll/new) is not the standard way. So it seems we'll need to capture the query string content and put it by hand on the rewriteRule. This should work (if you need it only for /admin url):

RewriteCond %{REQUEST_FILENAME} admin [NC]
RewriteCond %{QUERY_STRING} (.*) [NC]
RewriteRule .* index.php?uri=admin&q=%1 [L]

%1中第一个括号比赛中的RewriteCond:(。*),这意味着一切都在查询字符串,查询字符串是问号后,任何东西。所以其实这允许管理​​民调/新管理​​轮询/新和放大器;?富= TOTO ,使的index.php URI =管理及放大器; Q =轮询/新和放大器;富=酒吧

Where %1 is the first parenthesis match in the RewriteCond :(.*), meaning everything in the query string, the query string being anything after the question mark. So in fact this allows admin?poll/new but also admin?poll/new&foo=toto, giving index.php?uri=admin&q=poll/new&foo=bar

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

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