使用重写规则从URL中删除.php后,CSS和IMG文件有404


after remove .php from url with rewrite rule, css and img files have 404

我的网站和nginx服务器有问题.....从我的 url 地址中删除.php后,我的每个图像和 css 文件 404 都有错误。

有我的整个配置文件:

server {
        listen 80;
        server_name example.com;
        return 301 $scheme://www.example.com$request_uri;       
}
server {
        listen   80;
        root /usr/share/nginx/www;
        index index.php;
        server_name www.example.com;
        error_page 404 http://www.example.com/404.php;
        autoindex off;
        error_log  /usr/share/nginx/www/nginx_error.log  warn;
   location / {
        rewrite ^(.*)$ /$1.php;
    }
    location = / {
        rewrite ^ /index.php;
    }
    location ~ '.php$ {
        include fastcgi_params;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
    }
}

感谢您的所有意见!!问候马克罗马特

尝试将php重写限制为仅不带扩展名的URI:

rewrite ^([^'.]*)$ /$1.php;

或者,您可以通过在第一个location /块之前添加此块来完全排除图像:

location ~ '.(css|js|png|jpe?g|gif) { 
    # empty
}