NginXredirect

对于NginX的新手redirect,而不是我的正则expression式的忍者,有人可以请提供一些点,以便如何做一个理智的方式下面的301redirect

(为可怕的例子名称道歉)

website.com/what -> website.com/en/what website.com/team -> website.com/en/team website.com/stuff -> website.com/en/newstuff website.com/stuff/this -> website.com/en/newstuff/foo/bar website.com/stuff/that -> website.com/en/newstuff/thing/page 

虽然我很想有人给我确切的答案 – 我会解决一些好的指针或大致的例子,我需要做的或我应该采取的方向。

如果有帮助,我在Ubuntu 11上运行nginx 0.8x,网站本身是用CodeIgniter编写的,

最干净的方法是使用地图块。

 map $uri $new { /aa /en/aa; /bb /newstuff/bb; ^/cc/(?P<suffix>.*)$ /$suffix; /john /users/john/; } server { server_name www.example.com; rewrite ^ $new permanent; } 

这应该是基本的想法:

 server { listen 80; server_name website.com; root /var/www/website/current/public; location /what { rewrite /en/what/ redirect; } location /team { rewrite /en/team/ redirect; } }