2014-03-02 66 views
1

在我的重定向規則中,我有一個導致www2網站的路徑。www www2重定向的路徑nginx

重定向到其他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; 
    } 
} 
+0

[如果是邪惡的(http://wiki.nginx.org/IfIsEvil) – rvighne

回答

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

+0

謝謝對於穆罕默德的迴應。我很難獲得'try_files $ uri /index.php$request_uri;'來工作。 'index.php'文件實際上引導了應用程序,所以無論它在重定向之後運行什麼。我想這是特別棘手的。 –

相關問題