我有以下路线:
http://somehost/Project/Page/5/Contactgfmsdiojfdui9m
我希望将其永久重定向到:
http://somehost/Project/Page/5/Contact
我怎样才能完成过滤我不想支持的坏路由?
我有以下路线:
http://somehost/Project/Page/5/Contactgfmsdiojfdui9m
我希望将其永久重定向到:
http://somehost/Project/Page/5/Contact
我怎样才能完成过滤我不想支持的坏路由?
两种选择:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="ProjectPageContent_Redirect" stopProcessing="true">
<match url="^/Project/Page/(\d+)/Content.*" />
<action type="Redirect" url="/Project/Page/{R:1}/Content" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
RedirectPermanent
从控制器重定向控制器.cs
public class RedirectController : Controller
{
public ActionResult ProjectPageContent(Int32 id)
{
return RedirectPermanent(String.Format("/Project/Page/{0}/Content", id));
}
}
路由配置.cs
routes.MapRoute(
name: "ProjectPageContent_Redirect",
url: "/Project/Page/{id}/Contact{*extra}",
defaults: new { controller = "Redirect", action = "ProjectPageContent" }
);