Nginx不重定向php文件

时间:2011-02-14 13:21:45

标签: php nginx rewrite

每个文件都传递给“index.php”,但由于fastcgi,每个php文件都没有正确重定向。任何解决方法?

location / {
    if ($request_filename ~* "index.php") {
        break;
    }

    rewrite ^/(.*)$ /index.php?page=$1 last;

    break;
}

location ~* \.php$ {
    include fastcgi_params;

    fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;
    fastcgi_pass 127.0.0.1:9000;
}

由于

1 个答案:

答案 0 :(得分:2)

  1. 确保您的php源文件的根目录是:/ usr / share / nginx / html / else,修改fastcgi_pass ..
  2. 这是我的工作配置:

        location /media {
        if (-f $request_filename) {
                 # filename exists, so serve it
            break;
        }
    
        if (-d $request_filename) {
                 # directory exists, so service it
            break;
        }
        rewrite ^/(.*)$ /media/index.php?$1;
    }
    

    它会重定向所有不存在的请求,并且通常会向index.php返回404错误