如何在nginx配置中为重定向的url设置位置


How to set location in nginx configuration for redirected url?

我使用Zend Framework。这里是路由器初始化:

protected function _initRouter()
    {
        $router = Zend_Controller_Front::getInstance()->getRouter();
        $translatorRoute = new Zend_Controller_Router_Route(
                        ':lang/:controller/:action/*',
                        array(
                            'lang' => 'en',
                            'controller' => 'index',
                            'action' => 'index'
                        )
        );
        $staticRouter = new Zend_Controller_Router_Route(
                        '/:lang/s/:name',
                        array(
                            'lang' => 'en',
                            'controller' => 'static',
                            'action' => 'index',
                            'name' => ''
                        )
        );
        $router->addRoute('translator', $translatorRoute);
        $router->addRoute('static', $staticRouter);
        return $router;
    }

因此example.com/将被定向到example.com/en/

这是我的nginx配置:

server {
    server_name example.com www.example.com;
    charset UTF-8;
    disable_symlinks if_not_owner from=$root_path;
    index index.php;
    root $root_path;
    set $root_path /var/www/example.com;
    listen 80;
    include /etc/nginx/vhosts-includes/*.conf;
    location /application/                { deny all; }
    location / {
        try_files $uri $uri/ $root_path/index.php$is_args$args;
    }
    location ~ '.php$ {
        try_files $uri =404;
        fastcgi_index index.php;
        root $root_path;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include        fastcgi_params;
        fastcgi_intercept_errors on;
   }   
}

example.com被重定向到example.com/en/well,但example.com/en/返回404错误。如果我添加位置部分:

location /en/ {...

我们将得到递归。如何避免它并运行/en/page?

您是否应该使用regexp进行此类rediretc?或者使用*/en位置。