如何在重定向网址的nginx配置中设置位置?

时间:2015-02-22 12:14:24

标签: zend-framework nginx routing php

我使用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/,但是example.com/en/会返回404错误。如果我添加位置部分:

location /en/ {...

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

1 个答案:

答案 0 :(得分:0)

可能你应该使用regexp进行这样的重定向?或使用* / en location。