【问题标题】:How to rewrite path to url with semicolon in nginx?如何在nginx中用分号重写url的路径?
【发布时间】:2018-08-21 04:25:08
【问题描述】:

我使用 nginx 作为反向代理,Angular Universal 应用程序在后台提供服务。

我正在尝试通过 nginx 将旧的 URL 模式重写为新的,即

server {
    rewrite ^/s/(.+)$ /search\;q=$1 permanent;`
    ...
}

这样/s/keywords 之类的东西就会被重定向到/search;q=keywords

不幸的是,上面的nginx规则变成了

/s/keywords 转换为 /search/;q=keywords(因此在 /search 之后添加了一个斜线)。有没有机会删除这个斜线所以结果是/search;q=keywords

(在 nginx 后面运行的应用程序期望 url 为/search;q=keywords。)

【问题讨论】:

    标签: nginx url-rewriting


    【解决方案1】:

    您可以在替换中添加引号,例如:

    rewrite ^/s/(.+)$ "/search;q=$1" permanent;
    

    【讨论】:

      猜你喜欢
      • 2019-01-13
      • 1970-01-01
      • 2016-11-27
      • 2019-08-27
      • 1970-01-01
      • 2017-07-05
      • 1970-01-01
      • 2022-11-03
      • 2022-11-22
      相关资源
      最近更新 更多