2016-11-20 35 views
0

我想我重写规则只捕获的第一场比赛,而忽略其余改写比赛只有第一次出现

当前行为

https://domain.com/oliver.stack => oliver 
https://domain.com/oliver.stackoliver.stack => oliver.stackoliver 

期望的行为

https://domain.com/oliver.stack => oliver 
https://domain.com/oliver.stackoliver.stack => oliver 

Nginx的重写规则

location ~ .stack$ { 
     rewrite ^/(.*).stack$ /vid.php?v=$1; 
    } 

回答

1

stack$将在行(最终$)的末尾匹配“堆栈”。此外,.*是贪婪的:它会尝试匹配最长的字符串。 .*?是非贪婪版本:

rewrite ^/(.*?)\.stack /vid.php?v=$1; 
+0

感谢您的解释 – user2650277