Nginx简单重写

The*_*Kid 0 nginx url-rewriting

我想在nginx中创建以下url

comments.php?id=34
Run Code Online (Sandbox Code Playgroud)

/comments/34
/comments/34/
Run Code Online (Sandbox Code Playgroud)

我正在尝试这个,它的工作原理

rewrite  ^/comments/$id/(.*)$  /comments.php?id=$1?  last;
Run Code Online (Sandbox Code Playgroud)

我的问题是,如何强制重定向comments.php?id = x到/ comments/id

小智 6

rewrite ^/comments.php$ /comments/$arg_id? permanent;
Run Code Online (Sandbox Code Playgroud)