I'm trying to develop a custom route for this use case.
The following URL patterns:



should be redirected to https://example.com/products

The Brand & Product names in the URL may change, but the relative root will always be either /new or /used.

When I browse this URL - https://example.com/used/mybrand/myproduct.htm, it throws the error: enter image description here

Here is the code:


public class RouteConfig
        public static void RegisterRoutes(RouteCollection routes)

            routes.MapRoute("OldUsed", "used/{make}/{name}", new
                controller = "RedirectToListing",
                action = "RedirectOldVdpToVlp",
                make = "",



public class InitializeRoutes : Sitecore.Mvc.Pipelines.Loader.InitializeRoutes
        public override void Process(PipelineArgs args)


<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
        <processor type="Feature.Base.Pipelines.InitializeRoutes, Feature.Base" patch:before="processor[@type='Sitecore.Mvc.Pipelines.Loader.InitializeRoutes, Sitecore.Mvc']" />

Is this the right way.

  • 3
    If it helps you could try implementing rewrite/redirect rules in IIS instead of having custom routes defined Mar 24, 2021 at 14:12
  • @CristiVulturar I also need to handle some business logic, like getting the brand name from the old url and then redirect to the listing page with that as a query string param. Would that be possible. If yes, could you please share any references.
    – sukesh
    Mar 24, 2021 at 14:14
  • 2
    You can use redirect rules with regular expressions and backreferences. That is possible. This is just one blog about it: isitoktocode.com/post/…
    – Gatogordo
    Mar 24, 2021 at 14:36
  • 1
    Did you add htm extension to Allowed extensions in <processor type="Sitecore.Pipelines.PreprocessRequest.FilterUrlExtensions, Sitecore.Kernel">? If this is not done Sitecore will not run httpRequestBegin pipeline
    – Jeroen
    Mar 24, 2021 at 15:19
  • @Jeroen yes i did
    – sukesh
    Mar 24, 2021 at 15:36

1 Answer 1


You can use IIS Rewrite inbound rules to accomplish this, for example:

<rule name="Property URL Rewrite" stopProcessing="true">
   <match url="^new/Brand-([0-9]+)/Product-([0-9]+)$" />
   <action type="Rewrite" url="/products?brand={R:1}&amp;product={R:2}" appendQueryString="true" logRewrittenUrl="false" />
<rule name="Property URL Rewrite" stopProcessing="true">
    <match url="^used/Brand-([0-9]+)/Product-([0-9]+)$" />
    <action type="Rewrite" url="/products?brand={R:1}&amp;product={R:2}" appendQueryString="true" logRewrittenUrl="false" />

If you have links on the pages aswell you might need to create an outbound rule aswell to handle them, for example https://docs.microsoft.com/en-us/iis/extensions/url-rewrite-module/creating-outbound-rules-for-url-rewrite-module

  • Thank you. But can this not be done from code. As there could be some complex logic to be handled and also Brand & product were just examples. The names could be any alphanumeric strings.
    – sukesh
    Mar 24, 2021 at 15:02
  • For alphanumeric strings you can just change [0-9] to [0-9a-z]. From code you could also look into how the sitecore 301 redirect module is implemented, although that is doing redirect and not rewrite. We have relied on rewrite rules as it is easier to setup the parameters instead of custom routes. Mar 24, 2021 at 15:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.