Caio
Caio

Reputation: 3215

Nginx does not redirect php files

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

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

Thanks

Upvotes: 2

Views: 873

Answers (1)

sdolgy
sdolgy

Reputation: 7001

  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

Upvotes: 2

Related Questions