Welcome! Log In Create A New Profile

Advanced

Route non-existant .php requests through try_files?

June 14, 2012 11:24PM
Hi everyone,
I'm investigating moving one of my sites from another web server to Nginx. The app is a PHP app that uses the "front controller" pattern (everything routes via index.php), and the app takes care of URL routing and handling 404 errors.

My nginx site configuration looks something like this:
=====
server {
listen 8080;
server_name example.com;
root /var/www/example/live/public/;
index index.htm index.php;

location / {
try_files $uri /index.php;
}

location /assets/cache/ {
expires max;
}

location ~ \.php$ {
include fastcgi_params;
fastcgi_pass php;
fastcgi_param FUEL_ENV production;
}
}

upstream php {
server unix:/var/run/php5-fpm/www.sock;
}
=====

This works mostly as expected - Going to the root of the site hits the app's homepage, and the sub pages work (so example.com/about loads file). However if I go to a non-existent PHP file (like example.com/about.php), I get a white page that says "File not found." There's some legacy links that have ".php" at the end and routing these to the correct location is handled in the app itself. Because of my try_files setting, I expected this to go through index.php, like the URLs without extensions. However this doesn't seem to be the case. Anyone know how to configure it so it works this way?

tl;dr: How do I get requests to non-existent .php files to route via my index.php file?
Subject Author Posted

Route non-existant .php requests through try_files?

Daniel15 June 14, 2012 11:24PM

Re: Route non-existant .php requests through try_files?

Francis Daly June 15, 2012 03:56AM

Re: Route non-existant .php requests through try_files?

Daniel15 June 15, 2012 11:58PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 315
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready