Try our conversational search powered by Generative AI!

Url rewriting to shorturl

Vote:
 

I am a bit baffled on how to accomplish this. We have successfully converted their site awhile back from Drupal to EPiServer 7.  Pre (EPiserver 7.5).  They are abit annoyed that when they specify a short url, that is not the link the user is presented with as the link.  Yes, it response to the short url but they want the short url to be the url users see.  Any help would be appreciated.

#81667
Feb 23, 2014 20:06
Vote:
 

I'm not sure this is the correct way to handle this problem, and the solution is from a EPi 6 project. We created created a new URL-rewriter (might work to attach to an event instead, but we had some other functionality the needed a own rewriter), and in that rewriter we did: 

protected override bool ConvertToExternalInternal(EPiServer.UrlBuilder url, object internalObject, System.Text.Encoding toEncoding)
        {

            if (!PageReference.IsNullOrEmpty(internalObject as PageReference))
            {
                var page = DataFactory.Instance.GetPage((PageReference)internalObject);
                if (page != null && page.LinkType == PageShortcutType.Normal && page["PageExternalURL"] != null)
                {
                    url.Path = "/" + page["PageExternalURL"];
                    url.QueryCollection.Remove("id");
                    url.QueryCollection.Remove("epslanguage");
                    return true;
                }
            }

            return base.ConvertToExternalInternal(url, internalObject, toEncoding);
        }

    

#81671
Feb 23, 2014 22:10
Vote:
 

The above solution Erik suggests will work for WebForms but not for MVC (since MVC responoses does not pass through the FURL parsing). Another alternative is to attach an eventHandler to EPiServer.Web.Routing.ContentRoute.VirtualPathCreated. In the eventhandler you could load the content item and see if it has an simple address and if so replace the Url in the event argument (similar to the code above).

#81699
Feb 24, 2014 14:08
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* 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.