GET参数不重写规则被正确传递重写、正确、规则、参数

由网友(回忆、你的笑)分享简介:我写了一个简单的正则表达式我的应用程序的API:I wrote a simple regex for my application's API:^api/([^/]+)/([^/.]+)\.([^$/?=&]+)(?:\?(.*))?$这成为/app/api/$1.php?action=$2&format=$3&...

我写了一个简单的正则表达式我的应用程序的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]

调整你的重写规则相应。

阅读全文

相关推荐

最新文章