nginx rewrite WITHOUT change url

后端 未结 2 974
温柔的废话
温柔的废话 2020-12-24 08:09

I want to use rewrite function in my nginx server.

When I try \"http://www.example.com/1234\", I want to rewrite \"http://www.example.com/v.php?id=1234\" and want to

相关标签:
2条回答
  • 2020-12-24 08:15

    In my case, I needed to use 'last' to make it work due I had other rules that I wanted to be applied:

    location ~ /[0-9]+ {
        rewrite "/([0-9]+)" /v.php?id=$1 last;
    }
    
    0 讨论(0)
  • 2020-12-24 08:40

    Reference: http://wiki.nginx.org/HttpRewriteModule#rewrite

    If the replacement string begins with http:// then the client will be redirected, and any further >rewrite directives are terminated.

    So remove the http:// part and it should work:

    location ~ /[0-9]+ {
            rewrite "/([0-9]+)" /v.php?id=$1 break;
    }
    
    0 讨论(0)
提交回复
热议问题