Nginx URL rewrite for Zend Framework application as a subdirectory


Nginx is an increasingly popular web server for web development these days. URL Rewrite in Nginx is simple and powerful but kind of tricky to beginner users of Nginx. While there are numerous examples on how to rewrite URL for Nginx to run Zend application on a virtual host level, there is hardly any working example on how to configure at the subdirectory level.


So today we would like to share how you can do URL rewrite for running Zend framework application on Nginx at a subdirectory level like


So to get to the point, following is how you do it.

Nginx Configuration

        location ^~ /myproject {

                try_files $uri $uri/ /myproject/index.php$is_args$args;

                location ~ .php$ {
                #       fastcgi_split_path_info ^(.+.php)(/.+)$;
                #       # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
                #       # With php5-cgi alone:
                #       # With php5-fpm:
                #       fastcgi_pass unix:/var/run/php5-fpm.sock;
                        fastcgi_index index.php;
                        fastcgi_param APPLICATION_ENV production; #set your Zend environment name here
                        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
                        include fastcgi_params;