2015-01-26 68 views
0

我正在使用nginx。我想重寫網址。我的代碼:nginx重寫規則php的旋律

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

網址示例: 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=$2 last; 

回答

1

大括號{9}最有可能給你的正則表達式的一個問題。用下面的引號圍繞規則並嘗試。

rewrite "^/([^/]*)_([a-zA-Z0-9]{9}).html$" /watch.php?vid=$2 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