【问题标题】:Rewrite part of request url as variable on php script with nginx使用 nginx 将请求 url 的一部分重写为 php 脚本上的变量
【发布时间】:2012-07-19 02:07:31
【问题描述】:

我想要做的是:

domain.com/account/manage/somekey/  ->  domain.com/account/manage/?key=somekey
domain.com/account/manage/somekey/settings/  ->  domain.com/account/manage/settings/?key=somekey

somekey 是一个包含 A-F,a-f,0-9 长度为 24 个字符的字符串。

这是我的第一个,但我不确定如何做第二个。

location /account/manage/  {
     rewrite "^/account/manage/([A-Fa-f0-9]{24})/(.*)$" /account/manage/?key=$1;

    }

【问题讨论】:

    标签: regex nginx rewrite


    【解决方案1】:
    location /account/manage/ {
        rewrite "^/account/manage/([A-Fa-f0-9]{24})/(settings/)?" /account/manage/$2?key=$1;
    }
    

    【讨论】:

      【解决方案2】:

      我对nginx没有太多经验,但是试试这个版本:

      location /account/manage/$  {
        rewrite ^/account/manage/([A-Fa-f0-9]+)(/[^/]*)?/?$ /account/manage$2/?key=$1;
        try_files $uri $uri/;
      }
      

      【讨论】:

        猜你喜欢
        • 2019-02-05
        • 2016-12-18
        • 1970-01-01
        • 2019-01-19
        • 1970-01-01
        • 2022-08-19
        • 2020-07-24
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多