【问题标题】:after remove .php from url with rewrite rule, css and img files have 404使用重写规则从 url 中删除 .php 后,css 和 img 文件有 404
【发布时间】:2013-11-27 21:31:33
【问题描述】:

我的网站和 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 css .htaccess nginx


    【解决方案1】:

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

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-08
      • 2011-09-07
      • 1970-01-01
      • 2011-08-20
      相关资源
      最近更新 更多