Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Philip Christianto 20 posts 150 karma points
    Feb 01, 2017 @ 13:34
    Philip Christianto
    0

    Hi,

    I'm looking for a way to redirect all pages under a node without using the template page so for example opening

    www.domain.com/products/car/volvo

    will redirect to

    www.domain.com/products

    same with

    www.domain.com/products/car

    will redirect to

    www.domain.com/products

  • Ronish Potiah 19 posts 171 karma points
    Feb 01, 2017 @ 15:09
    Ronish Potiah
    0

    Hi Philip,

    Suppose content A needs to redirect to Content B.

    In that case, you need to modify the document type of A and add new property: umbracoRedirect of type content picker.

    Then on content A, you need to select content B on the redirect field. This will do a 302 redirect.

    You can also use: umbracoInternalRedirectId of type content picker, this will not rewrite the url but will load content B.

    See here for more reserved properties from Umbraco

  • Philip Christianto 20 posts 150 karma points
    Feb 01, 2017 @ 15:18
    Philip Christianto
    0

    But this will make admin have to put redirect from the cms to everything under the node. Is there no other way? Perhaps modifying the web config?

  • Ronish Potiah 19 posts 171 karma points
    Feb 01, 2017 @ 15:33
    Ronish Potiah
    0

    Then you have to do it in code by creating a filter and use it on application started.

    ProductRedirectFilter.cs

    public class ProductRedirectFilter : ActionFilterAttribute
    {
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (filterContext.HttpContext.Request.Url.ToString().Contains("products"))
            {
                // find more efficient ways to check if url contains products
                // use regex to check for string after products/..../.../
    
                filterContext.Result = new RedirectResult("www.domain.com/products");
            }
        }
    }
    

    Add the filter in another class FilterConfig.cs

    public class FilterConfig
    {
        public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            filters.Add(new ProductRedirectFilter());
        }
    }
    

    Then on your application started event handler:

    public class YourApplication : ApplicationEventHandler
    {
        protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
            base.ApplicationStarted(umbracoApplication, applicationContext);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
        }
    }
    

    Not tested though, but should work.

  • Philip Christianto 20 posts 150 karma points
    Feb 01, 2017 @ 15:52
    Philip Christianto
    0

    will try and update tomorrow at work. Thanks!

Please Sign in or register to post replies

Write your reply to:

Draft