Nginx配置与Slim框架,如何保持.php的url


Nginx configuration with Slim Framework, How to keep the .php url

我的服务器刚刚被提供商删除,并且我没有Nginx配置文件的备份。我很幸运它还能用,现在我不知道该怎么办了。

所以我有多个文件做一些特定的事情,我在每个文件上使用Slim框架。这个想法是在URL上保留php扩展名。像这样:

www.example.com/service.php/customer/1
www.example.com/api.php/data
www.example.com/test.php/other-data/5

有人对此有什么线索吗?我真的忘了我之前对配置做了什么。

提前感谢

如果有人来了,我终于找到了答案。

server {
listen   80; ## listen for ipv4; this line is default and implied
root /usr/share/nginx/www;
index index.html index.htm;
# Make site accessible from http://localhost/
server_name localhost;
location / {
}
location /doc/ {
    alias /usr/share/doc/;
    autoindex on;
    allow 127.0.0.1;
    deny all;
}
location ~ [^/]'.php(/|$) {
    fastcgi_split_path_info ^(.+?'.php)(/.*)$;
    if (!-f $document_root$fastcgi_script_name) {
      return 404;
    }
    include fastcgi_params;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
}}

正如评论中建议的那样,重写url以便删除'.php'可能是一个更好的主意:

你的NGINX配置文件应该是这样的:

server {
    listen       80;
    server_name  example.org;
    rewrite ^/(.*).php/(.*) /$1/$2    //add this line to get rid of '.php'
}

详情请参阅:http://nginx.org/en/docs/http/ngx_http_rewrite_module.html

不要忘记在编辑完NGINX的配置后重启它。