Here’s my default route:
routes.MapRouteLowercase(
"Default",
"{country}/{controller}/{action}/{id}",
new {
country = "uk",
controller = "Home",
action = "Index",
id = UrlParameter.Optional
},
new[] { "Presentation.Controllers" }
);
As we know, when someone visits http://www.domain.com/ MVC’s routing will determine the default controller and action to execute based upon the above route, but the URL will remain the same. Is there a built in or elegant way to perform a 301 redirect from http://www.domain.com/ to http://www.domain.com/uk/{controller}/{action}/ for every route that uses defaults?
I have created a custom route handler that does the redirect at the route level. Thanks to Phil Haack.
Here is the complete work.
Redirect route handler
Redirect http handler
Route extensions
Having all these, I can do something like this while mapping routes in Global.asax.cs.