Can I change URL of content?

跟風遠走 提交于 2019-12-12 05:51:56

问题


I have created some contents. I have noticed URL of content is generated automatically based on name of content. Can you please guide me if I can edit URL or enter a custom URL ?

Thanks


回答1:


You can do it in 2 ways:

1

Setup these rules in UrlRewrite.config in /config folder in your umbraco websites root. To add new rule:

<add name="produktidrewrite" 
    virtualUrl="^~/product/(.*).aspx" 
    rewriteUrlParameter="ExcludeFromClientQueryString" 
    destinationUrl="~/product.aspx?productid=$1" 
    ignoreCase="true" />

2.

Or you can add a custom route in your code. Create a new class which inherit from Umbraco.Core.ApplicationEventHandler. Then overwrite ApplicationStarted to add your rules. Like this:

protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
    //Custom route
    RouteTable.Routes.MapRoute(
    "SomeName",
    "Something/{action}/{id}",
    new
    {
        controller = "MyController",
        action = "Index",
        id = UrlParameter.Optional
    });
}


来源:https://stackoverflow.com/questions/25635768/can-i-change-url-of-content

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!