www www2重定向nginx的路径

时间:2014-03-02 02:23:45

标签: nginx

在我的重定向规则中,我有一条指向www2网站的路径。

重定向到其他www类型的网站工作正常,所以我想知道我是否需要在这里添加一些我特别缺少的特殊内容。我需要清除缓存来传播这些变化吗?

location / {
    #This one doesn't work?
    if ( $request_filename ~ /foo0 ) {
        rewrite ^ http://www2.example.com/foo0 permanent;
    }

    #Works fine
    if ( $request_filename ~ /foo1) {
        rewrite ^ http://sub1.example.com/? permanent;
    }

    #Works fine
    if ( $request_filename ~ /foo2 ) {
        rewrite ^ http://sub2.example.com/? permanent;
    }

    #All other requests good.
    if (!-f $request_filename) {
        rewrite ^(.*)$ /index.php last;
    }
}

1 个答案:

答案 0 :(得分:1)

你可以用这样的东西替换这些

location ~ /foo0$ {
  return 301 http://www2.example.com/foo0;
}
location ~ /foo1$ {
  return 301 http://sub1.example.com;
}
location ~ /foo2$ {
  return 301 http://sub2.example.com;
}
location / {
  try_files $uri /index.php$request_uri;
}

避免使用Taxing rewritesusing if

相关问题