Nginx 重写相当于 Apache RewriteRule 将 URL params 转换为 QueryString key/value 对

Nginx rewrite equivalent to Apache RewriteRule that converts URL params into QueryString key/value pair

我正在执行从 Apache 服务器到 Nginx 的迁移,但错过了执行重写的 .htaccess 文件:

RewriteRule ^(.*)$ routes.php?params= [NC,QSA]

例如,此端点 example.com/api/v1/param1/param2/param3 将重写为 https://example.com/api/v1/routes.php?params=/param1/param2/param3

有人可以在我重新尝试迁移之前确认这是 Nginx 的正确等效项吗?

rewrite "(?i)^(.*)$" routes.php?params=

因为 /api/v1 是唯一需要重写的路径,所以在配置文件中是这样使用的吗?

location /api/v1 {
  rewrite "(?i)^(.*)$" routes.php?params=
} 

更新

将此添加到 Laravel Forge 中的 conf 文件似乎只会破坏应用程序并阻止显示任何视图。相反,它说 This site can’t be reached example.com refused to connect.

所有 nginx URI 都以前导 / 开头,并且您的正则表达式不会尝试在附加参数列表之前删除 /api/v1/ 前缀。

尝试:

location /api/v1 {
    rewrite ^/api/v1(/.*)$ /api/v1/routes.php?params= last;
}