Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to shorten the url to just the action parameter

If a website with url "www.site.com", redirects to HomeController's Index action.

I have

www.site.com/area/controller/action/{nick}

I want the url

www.site.com/{nick}

do the same thing

How I do to create a route and where do I have to create it?

In the RouteConfig.cs or in the AreaRegistration.cs?

like image 405
Andres Bernal Avatar asked Dec 10 '25 23:12

Andres Bernal


1 Answers

In your RouteConfig.cs, add following route after all routes.

routes.MapRoute
(
    name: "Nick Route",
    url: "{nick}",
    defaults: new { area = "AreaName",
                    controller = "controllerName",
                    action = "Actionname",
                    nick = UrlParameter.Optional  });
like image 129
Bhushan Firake Avatar answered Dec 13 '25 17:12

Bhushan Firake



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!