GET parameters not being correctly passed by RewriteRule

爱⌒轻易说出口 提交于 2019-12-24 07:31:24

问题


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

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

this becomes

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

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.


回答1:


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]

Adjust your RewriteRule accordingly.



来源:https://stackoverflow.com/questions/11760116/get-parameters-not-being-correctly-passed-by-rewriterule

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!