0

I originally had this maproute in my RouteConfig

            routes.MapRoute(
        name: "thread",              
        url: "{Areamix}/{urltitle}/{id}/thread",
        defaults: new {controller = "thread", action = "view"
        });

The routes with that were too long so I shorten this up to

            routes.MapRoute(
        name: "thread",              
        url: "{urltitle}/{Areamix}-{id}",
        defaults: new
        {
            controller = "thread",
            action = "view"
        });

As you already know the old webpages now return a 404 error since the routing URL has changed, how can I get the old indexed pages redirect or permanent redirect to the newer MapRoute ? They all share common features like the {id} any suggestions would be great thanks.

user1591668
  • 2,591
  • 5
  • 41
  • 84

1 Answers1

0

Leave the old MapRoute as it is but map it to a new Controller (action is now Redirect instead of view:

    routes.MapRoute(
      name: "thread",              
      url: "{Areamix}/{urltitle}/{id}/thread",
      defaults: new {controller = "thread", action = "Redirect" // Action is now Redirect (instead of view)
    });

Then, create a new Action in your Controller:

public ActionResult Redirect()
{
    // Now rebuild your url in new format:
    var link = RouteData.Values["urltitle"] + RouteData.Values["Areamix"] + "-" + RouteData.Values["id"];
    return RedirectPermanent(link);
}

Now all requests matching the old maproute go to the Redirect Action and are then formatted to the new maproute format.

I didn't test it but it should work like that.

Luca Steeb
  • 1,795
  • 4
  • 23
  • 44