2010-09-17 56 views
0

使用urlrewiter.net我試圖做301重定向到網站根的任何請求到一個新的目的地。例如如何將網站根網址重寫爲新的刪除?

www.example.com應該被重定向到www.example.com/en/

如何與urlrewriter.net我試過下面的規則,但沒有工作,實現這一目標或進入一個無限循環。

<redirect url="^www\.example\.com" to="/en/" /> 
    <redirect url="^www\.example\.com\/" to="/en/" /> 
    <redirect url="^www.example.com" to="/en/" /> 
    <redirect url="^www.example.com/" to="/en/" /> 
    <redirect url="/" to="/en/" /> 
    <redirect url="^/" to="/en/" /> 

任何人都知道如何做到這一點?

回答

0

如果您想匹配「www.example.com」而不是「www.example.com/en」(從而避免無限遞歸),則需要在正則表達式的末尾添加$符號。嘗試使用以下三條規則:

<redirect url="^www\.example\.com$" to="www\.example\.com/en/" /> 
<redirect url="^example\.com$" to="www\.example\.com/en/" /> 
<redirect url="^www\.example\.com/$" to="www\.example\.com/en/" /> 

向最後添加一個$符號表示表達式匹配字符串的結尾。因此,通過在開始處添加一個^和$到結尾,您可以強制您的表達式成爲整個字符串。我認爲你得到無限遞歸的原因是你使用的所有模式都匹配 「www.example.com/en/」,並將其重定向到自身,並將其重定向到自身,等等。

+0

請注意確定原因,但這些規則不起作用。這可能是默認頁面干擾了請求嗎? – webman 2010-09-17 05:30:27

+0

可能。試試''。 – AlcubierreDrive 2010-09-17 06:24:35