nginx 重写规则 php 旋律

nginx rewrite rule php melody

我正在使用 nginx。我想重写 urls。我的代码:

rewrite ^/([^/]*)_([a-zA-Z0-9]{9}).html$ /watch.php?vid= last;

url 示例: http://104.238.130.170/hudson-against-the-grain-video_14a4e06f8.html

但是当我保存文件然后重新启动 nginx 服务器时出现错误:

[emerg] directive "rewrite" is not terminated by ";" in /etc/nginx/conf.d/default.conf:46

问题:我的重写规则有什么问题?

rewrite ^/([^/]*)_([a-zA-Z0-9]{9}).html$ /watch.php?vid= last;

花括号 {9} 很可能在您的正则表达式中出现问题。用如下引号括起规则并尝试。

rewrite "^/([^/]*)_([a-zA-Z0-9]{9}).html$" /watch.php?vid= last;

Note: for curly braces( { and } ), as they are used both in regexes and for block control, to avoid conflicts, regexes with curly braces are to be enclosed with double quotes (or single quotes).

更多信息here