GET参数不重写规则被正确传递 [英] GET parameters not being correctly passed by RewriteRule

查看:113
本文介绍了GET参数不重写规则被正确传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个简单的正则表达式我的应用程序的API:

I wrote a simple regex for my application's API:

^api/([^/]+)/([^/.]+)\.([^$/?=&]+)(?:\?(.*))?$

这成为

/app/api/$1.php?action=$2&format=$3&$4

refiddle 正则表达式的作品完美,构建正确的URL,但PHP脚本没有报告任何GET参数除了动作格式参数。这是摆在/ htaccess的是

In the refiddle the regex works perfectly, constructing correct URLs, but the PHP script is not reporting any GET parameters apart from the action and format parameters. The .htaccess which is placed in / is

AddType image/svg+xml svg
RewriteEngine on
#If the URL is just /api, give them the docs
RewriteRule ^api/?$ /app/api/apidoc.php [L]
#Example api/user/update.json?x=fff&y=gggg
#http://refiddle.com/2ss
RewriteRule ^api/([^/]+)/([^/.]+)\.([^$/?=&]+)(\?(.*))?$ /app/api/$1.php?action=$2&format=$3&$4 [L]
#Example api/user/update?x=000&y=ffe
RewriteRule ^api/([^/]+)/([^/.&=]+)(\?((.*)*))?$ /app/api/$1.php?action=$2&$3 [L]

在此先感谢。

Thanks in advance.

推荐答案

不要试图捕捉更多的查询字符串参数。相反,它们附加与 QSA 标志。

Don't try to capture additional query string parameters. Instead, append them with the QSA flag.

RewriteRule ^api/([^/]+)/([^/.]+)\.([^$/?=&]+) /app/api/$1.php?action=$2&format=$3 [L,QSA]

调整你的重写规则相应。

这篇关于GET参数不重写规则被正确传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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