tags:

views:

21

answers:

1

Using urlrewiter.net i am trying to do a 301 redirect of any requests to the website root to a new destination. e.g

www.example.com should be redirected to www.example.com/en/

How can i achieve this with urlrewriter.net i've tried the following rules but none work or go into an infinite loop.

    <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/" />

Anyone know how to do this?

A: 

If you want to match "www.example.com" but not "www.example.com/en" (and thus avoid infinite recursion), you need to add a $ sign to the end of the regex. Try using these three rules:

<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/" />

Adding a $ sign to the end mandates that the expression match the end of the string. So by adding a ^ to the beginning and a $ to the end, you can mandate that your expression be the entire string. I think the reason you were getting infinite recursion was the patterns you were using all match "www.example.com/en/" and redirect it to itself, which redirects it to itself again, etc.

Jon Rodriguez
note sure why but these rules don't work. Could it be that the default page is interfering with the request?
webman
Could be. Try `<redirect url="^www\.example\.com/NAME_OF_YOUR_DEFAULT_PAGE$" to="www\.example\.com/en/" />` .
Jon Rodriguez