November Happy Hour will be moved to Thursday December 5th.
AI OnAI Off
November Happy Hour will be moved to Thursday December 5th.
Override and implement your own friendly URL provider and add the logic there. I've simply used the pageid for this previously. Eg: www.sitename.com/212.
Hope this helps.
Frederik
Hi Frederik,
Which URL provider do you use? Any more help would be great - talking to a coding novice to be honest!
Thanks.
Something like (using page id):
using System.Web; using EPiServer; using EPiServer.Core; namespace xxxx.UrlRewrite { public class FriendlyUrlRewriteProvider : EPiServer.Web.FriendlyUrlRewriteProvider { public string RedirectUrl { get; set; } public override bool TryConvertToInternal(EPiServer.UrlBuilder url, out System.Globalization.CultureInfo preferredCulture, out object internalObject) { //Use the default rewriting behavior if (base.TryConvertToInternal(url, out preferredCulture, out internalObject)) { return true; } HttpContext context = HttpContext.Current; if (IsValidShortEPiServerUrl(context)) { PerformRedirect(context); } return false; } private bool IsValidShortEPiServerUrl(HttpContext context) { string path = context.Request.Url.Segments[1]; int pageId; if (int.TryParse(path, out pageId)) { var pageReference = new PageReference(pageId); try { PageData destinationPage = DataFactory.Instance.GetPage(pageReference); SetRedirectUrl(destinationPage); return true; } catch (PageNotFoundException ex) { return false; } } return false; } private void SetRedirectUrl(PageData destinationPage) { RedirectUrl = destinationPage.LinkURL; } private void PerformRedirect(HttpContext context) { context.ClearError(); string url = RedirectUrl; context.Response.Clear(); context.Response.StatusDescription = "Moved Permanently"; context.Response.StatusCode = 301; context.Response.RedirectLocation = url; context.Response.End(); } } }
Then you need to update the default URL provider used in episerver.config:
<urlRewrite defaultProvider="CustomFriendlyUrlRewriteProvider"> <providers> <add name="EPiServerFriendlyUrlRewriteProvider" type="EPiServer.Web.FriendlyUrlRewriteProvider,EPiServer" /> <add name="CustomFriendlyUrlRewriteProvider" type="xxxx.UrlRewrite.FriendlyUrlRewriteProvider, xxxx" /> <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" /> </providers> </urlRewrite>
Frederik
Marc, if it's only a few pages that you want to shorten, then you can use "Simple address for this page" under the "Settings" tab. If you want to shorten all pages, then Frederiks approach might be handier. :)
Hi All,
Is there a way in EPiServer (or another method anyone knows about) to change a URL such as http://www.sitename.com/en/I-am-a-page-with-a-really-long-name/I-am-a-page-with-a-really-long-name/ to www.sitename.com/shorturl
Many Thanks.