Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rewrite or change routing in asp.net MVC URL?

I want to be able to rewrite my URL's to a single level URL. This means that i need to make a dynamic(will change in each language) rewrite rule, like this:

Original Url: http://www.mydomain.com/account/pages/13

I always want to show the URL in a single level:

http://www.mydomain.com/my-page-title

never no more than one slash / after the domain name.

I also need to be able to translate the page title in the above example:

http://www.mydomain.com/my-translated-page

How do I achieve this, and it should be able to change this on runtime - that is to "improve" the url, just like rewrite rules in htaccess

like image 455
Brian Hvarregaard Avatar asked Mar 17 '14 22:03

Brian Hvarregaard


1 Answers

You have to create your own Routes. As you are using the MVC4 put this custom route above the Default Route of the Application.

 routes.MapRoute(
      name: "Custom_Route",
      url: "My-Page-Title/{id}",
      defaults: new { controller = "Home", action = "About", id = UrlParameter.Optional }
 );

And for translating a Url in Mvc

like image 149
Bhupendra Shukla Avatar answered Sep 26 '22 02:09

Bhupendra Shukla