Try our conversational search powered by Generative AI!

Custom URL Rewriting in 7.5



WE have a custom url rewriter that inherits from the FriendlyUrlRewriter and this does not work with 7.5 any longer. We have tried changing the functionality to inherit from the hierarchicalUrlRewriterProvider, but this is missing a function: ConvertToInternalInternal. 

My question is how do I recreate this functionality? The functionality is basically as follows : 

protected override bool ConvertToInternalInternal(UrlBuilder url, ref object internalObject)
            bool urlRewritten = false;
            KeyValuePair qsAdditional = new KeyValuePair();

            if (url != null)
                PageReference pageRef = null;

                if (!url.Path.ToLower().StartsWith("/events/"))  // Don't try to resolve a link that starts with 'events' as this has already been rewritten
                    pageRef = TryResolveEventsUrl(url);

                    if (PageReference.IsNullOrEmpty(pageRef))
                        pageRef = TryResolveBusinessLineClaimsUrl(url, out qsAdditional);

                    if (!PageReference.IsNullOrEmpty(pageRef))
                        // Rewrite the url based on the page ref
                        url.Path = new Url(DataFactory.Instance.GetPage(pageRef).StaticLinkURL).Path;

                        // Add the page id back to the querystring
                        url.QueryCollection.Add("id", pageRef.ID.ToString());

                        // Add additional querystring parameters to the internal url
                        url.QueryCollection.Add("epslanguage", ContentLanguage.PreferredCulture.TwoLetterISOLanguageName);

                        // Add any additional querystring parameters
                        if (!String.IsNullOrEmpty(qsAdditional.Key))
                            url.QueryCollection.Add(qsAdditional.Key, qsAdditional.Value);

                        urlRewritten = true;

            if (urlRewritten)
                return true;
            else //Not a custom url so use default rewriting behaviour
                return base.ConvertToInternalInternal(url, ref internalObject);


Thank you! 


Aug 20, 2015 14:20


Did you tried to override TryConvertToInternal method of HierarchicalUrlRewriteProvider?

 public override bool TryConvertToInternal(UrlBuilder url, out CultureInfo preferredCulture, out object internalObject)
      preferredCulture = ContentLanguage.PreferredCulture;
Aug 20, 2015 15:20

Thank you Gregorz. I had the ConvertToInternal method implemented, so the tryconvert would have done the same functionality. 

The problem was that the RewriteProvider was not hooked up in the episerver config correctly, and the RewriteModule was not set to EPiServer.Web.RoutingUrlRewriteModule. 

according to the documentation : this is what's required to make it work. 

So in Web config, I have a module registered under system.web> httpModules: 

      <add name="UrlRewriteModule" type="EPiServer.Web.RoutingUrlRewriteModule, EPiServer" />

In Episerver.config I set the urlRewrite section up as follows: 

 <urlRewrite defaultProvider="CustomUrlRewriter">
      <clear />
      <add description="EPiServer standard Friendly URL rewriter" name="EPiServerFriendlyUrlRewriteProvider" type="EPIServerFriendlyUrlRewriter,EPiServer" />
      <add description="EPiServer identity URL rewriter" name="EPiServerIdentityUrlRewriteProvider" type="EPiServer.Web.IdentityUrlRewriteProvider,EPiServer" />
      <add description="EPiServer bypass URL rewriter" name="EPiServerNullUrlRewriteProvider" type="EPiServer.Web.NullUrlRewriteProvider,EPiServer" />
      <add name="CustomUrlRewriter" type="CustomUrlRewriter,MyAssemblyName" />

Thanks for your help!

Aug 21, 2015 10:08
<p>Thnaks Gabor for explaining solution.</p> <p>/K</p>
Aug 21, 2015 12:46
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.