tags:

views:

40

answers:

1

I am working on a multilingual website where the URL will contain the language code:

/en/Home

/es/Home

Whenever someone enters a url that does not have the language code at the beginning (/Home), I would like to do a 301 redirect to the url (route) they entered but append the language code at the beginning. I will determine the language to redirect to based on the language setting of their browser (HttpContext.Request.UserLanguages).

Since I will have logic within MVC, I cannot use the IIS7 URL rewriting.

I am not sure if it would be best to create a custom HttpHandler or RouteHandler or something else.

A: 

Check out this blog for a way to handle localization in ASP.NET MVC: http://helios.ca/2009/05/27/aspnet-mvc-and-localization/

Not what you were asking for specifically but an interesting approach.

Hightechrider
Actually, I am using that exact approach (code) to set the culture info of the current thread to the language. As you can see from their example, the SetCultureAttribute looks for the current culture in a Cookie, Session and browser setting. I am hoping to only look at the URL (by reading RouteData.Values["language"]), so before SetCultureAttribute kicks in, I would like to make sure the language code is in the URL, if not, force the language code by doing a redirect.
Andy
If you *really* want the language at the beginning you could create a catch-all route after you've created all the others and have the controller for that catch-all route handle the redirect. routes.MapRoute("Catch All", "{*path}", ...}
Hightechrider