如何将nginx中的根域重定向到另一个URL

时间:2014-04-19 08:15:55

标签: nginx

我需要将根路径单独重定向到特定的URL和其他路径的其他路径。

例如:

http://localhost/example should be redirected to http://localhost/example/index.php?route=common/home

http://localhost/example/welcome-to-this should be redirected to http://localhost/example/index.php?route=welcome-to-this

我试过这种方式

  location /example {
         rewrite ^ /example/index.php?_route_=common/home last;
   }
   location /example/(.*)$ {
        rewrite ^/(.+)$ /example/index.php?_route_=$1 last;
    }

1 个答案:

答案 0 :(得分:0)

试试这个:

location = /example {
    return 301 $scheme://$host/example/index.php?route=common/home;
}

location ~ ^/example/(.*)$ {
    return 301 $scheme://$host/example/index.php?route=$1;
}