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

为君一笑 提交于 2019-12-06 14:54:05

If somehow someone goes here, I finally found the answer.

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;
}}

As suggested in the comments, it's probably a better idea to rewrite your urls so that '.php' is removed :

Your NGINX configuration file should then look like this :

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

See : http://nginx.org/en/docs/http/ngx_http_rewrite_module.html for in-depth information.

Don't forget to restart your NGINX service after editing its configuration.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!