I am setting up an nginx
server to be used with the Zend Framework. For the most part it works. However, if there is a trailing slash on the end of a URL, for example http://localhost/test/
vs http://localhost/test
, the URL with a trailing slash will not work. This is unexpected and unfortunate. I want it to work for both URLs.
What should I do to resolve this? My nginx configuration is:
server {
listen 80;
server_name mywebsite.com;
root /var/www/site/public;
location / {
rewrite ^/(.*)/$ /$1;
include /etc/nginx/fastcgi_params;
fastcgi_param APPLICATION_ENV development;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/site/public/index.php;
}
}
As you can see I've tried to add a rewrite condition but it isn't seeming to make a difference.
Best Answer
Here's a pair of config files that I use for Zend Framework applications. First,
php.conf
, which I share between projects on my development workstation. I keep this at a directory above mysites
directory, right in the nginx config root (e.g./usr/local/etc/nginx/php.conf
):And then the
server
block that makes use of that:In your case, I think the key bit is
try_files $uri $uri/ /index.php$is_args$args;
, where we just pass the URL and query string wholesale toindex.php
, and let it do the parsing.