2010-09-17 84 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