2017-03-06 127 views
1

到现在,我有我的API是根,为exmple前值:https://api.example.comnginx的设置URL重写规则

,因为我使用CI,我需要每路径改写为指数,像这样:

location/{ 
    try_files $uri $uri/ /index.php?q=$uri&$args 
} 

现在,我搬到版本的API,所以每个版本都是在一个子目录,例如:https://api.example.com/0.0.1/

我怎样才能改变我的规则,以适应新的模式? (如果文件夹,然后东西,使用该文件夹的索引)

回答

1

我假定你想一个通用的解决方案,在这种情况下,你可以卸载改写到一个名为位置:

location/{ 
    try_files $uri $uri/ @rewrite; 
} 
location @rewrite { 
    rewrite ^(/\d\.\d\.\d)(/.*)$ $1/index.php?q=$2&$args last; 
    rewrite^     /index.php?q=$uri&$args last; 
} 

this document更多。