保留 GET 参数的 RewriteRule [英] RewriteRule that preserves GET parameters

查看:21
本文介绍了保留 GET 参数的 RewriteRule的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个重写规则有什么问题?

What is wrong with this rewrite rule?

RewriteRule ^api/(.+)$ api/index.php?url=$1 [L]

我只是想在 api/之后和其余的 get 参数之前添加index.php?url=".

I simply want "index.php?url=" to be added after api/ and before the rest of the get parameters.

api/image/upload&arg1=1&text=lorem+ipsum

api/index.php?url=image/upload&arg1=1&text=lorem+ipsum

(.+) 在 api/之后获取所有内容有什么问题?

What is wrong with (.+) to get everything after api/?

推荐答案

RewriteRule 上的正则表达式仅针对 URL 的路径部分运行,而不针对查询参数.幸运的是有 [QSA] 标志 保留现有的查询参数.

The regex on the RewriteRule is only run against the path part of the URL, not the query parameters. Fortunately there is the [QSA] flag to preserve existing query parameters.

这篇关于保留 GET 参数的 RewriteRule的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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