nginx重写条件仅适用于根文件夹(不适用于子文件夹)

时间:2015-06-11 11:10:13

标签: php apache mod-rewrite nginx

我正在使用apache的nginx进行静态内容服务。我有一个重写规则,它将所有丢失的php文件重定向到特定的(index.php)文件。但目前该规则适用于根文件夹(包括子目录)中的任何位置。我想让它只适用于/目录而不是子目录。例如,如果我访问http://www.domain.com/someting/missing.php,我想获得404代码。但是,如果我仍然访问http://www.domain.com/missing.php以获得index.php
到目前为止,这是我的代码:

location ~ \.php$ {
proxy_pass http://ip:7777;
proxy_set_header Host             $host;
proxy_set_header X-Real-IP        $remote_addr;
proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
proxy_set_header X-Accel-Internal /internal-nginx-static-location;
access_log off;
try_files $uri @missing;
}

location @missing {
 rewrite ^ /index.php last;
}

0 个答案:

没有答案
相关问题