博客路由修改,可是网站已有收录,点击原来的链接,会提示找不到页面,就做了个301重定向。
//自定义路由一定要放在前面 routes.MapRoute( name: "Article Old", url: "Articles/{id}", defaults: new { controller = "Redirect", action = "OldDetails", id = UrlParameter.Optional } ); //routes.MapRoute( // name: "Article", // url: "Articles/{id}", // defaults: new { controller = "Article", action = "Details", id = UrlParameter.Optional } //);
_ueditor_page_break_tag_
注销部分为原来的路由,Article Old为做301重定向的路由。还需要新建个控制器RedirectController
//301重定向 public ActionResult OldDetails(int? id) { if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } return RedirectPermanent("/Article/" + id); }
整个功能是实现blog.uoolo.com/Articles/1到blog.uoolo.com/Article/1的跳转。
参考文章:http://stackoverflow.com/questions/16979234/asp-net-mvc-4-301-redirects-in-routeconfig-cs