简体   繁体   中英

nginx rewrite rule php melody

I am using nginx. I want to rewrite urls. My code:

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

Example of url: http://104.238.130.170/hudson-against-the-grain-video_14a4e06f8.html

But when I save file then restarts nginx server i got error:

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

QUESTION: What is wrong on my rewrite rule?

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

The curly brackets {9} are most likely giving a problem in your regex. Surround the rule with quotes like below and try it.

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).

More info here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM