开发者

Nginx does not redirect php files

开发者 https://www.devze.com 2023-02-10 04:06 出处:网络
Every file is passed to \"index.php\", but every php file isn\'t properly redirected because of the fastcgi. Any workaround ?

Every file is passed to "index.php", but every php file isn't properly redirected because of the fastcgi. Any workaround ?

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

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

    break;
}

location ~* \.php$ {
    include fas开发者_高级运维tcgi_params;

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

Thanks


  1. Make sure the root directory for your php source file is: /usr/share/nginx/html / else, modify the fastcgi_pass ..

This is a working configuration I have:

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

It will redirect all requests that do not exist and would normally return a 404 error to the index.php

0

精彩评论

暂无评论...
验证码 换一张
取 消