File Nginx:与try\u文件一起使用重写

File Nginx:与try\u文件一起使用重写,file,nginx,rewrite,File,Nginx,Rewrite,我正在尝试使用rewrite和try\u文件一起使用。理想情况下,我希望Nginx首先尝试原始URI。如果不起作用,请尝试控制器/controllers/$1.php。最后,只需重定向到索引。这就是我到目前为止所做的(为了简洁,我牺牲了上面提到的理想顺序): 不过,这似乎不起作用。有什么想法吗 location / { try_files $uri $uri/ /controllers$uri.php; location ~ \.php$ { try_files

我正在尝试使用
rewrite
try\u文件一起使用。理想情况下,我希望Nginx首先尝试原始URI。如果不起作用,请尝试控制器
/controllers/$1.php
。最后,只需重定向到索引。这就是我到目前为止所做的(为了简洁,我牺牲了上面提到的理想顺序):

不过,这似乎不起作用。有什么想法吗

location / {
    try_files $uri $uri/ /controllers$uri.php;

    location ~ \.php$ {
        try_files $uri /index.php;

        #
        # fastcgi/proxy_pass php configuration
        #
    }
}

您似乎不了解重写模块是如何工作的。请阅读:但对于您的情况,您根本不需要重写模块。您似乎不了解重写模块是如何工作的。请阅读:但对于您的案例,您根本不需要重写模块。工作非常有魅力!是的,是时候坐下来仔细阅读一下文档了……工作起来很有魅力!是的,是时候坐下来仔细阅读一下文档了。。。
location / {
    try_files $uri $uri/ /controllers$uri.php;

    location ~ \.php$ {
        try_files $uri /index.php;

        #
        # fastcgi/proxy_pass php configuration
        #
    }
}