We are migrating to episerver 5.0 R2 and wre came across the following issue.
We have a episeserver page UKContactUsPage under tree structure : SiteName/ContactUs/Country/UKContactUsPage
i.e : Simple Address for the page : UKContactUsPage
A simple address (Friendly URL) is set for the page as : UK
When we browse to the page as http://sitename/UK , it should redirect the user to the full address (i.e http://sitename/SiteName/ContactUs/Country/UKContactUsPage)
The page is served as expected, which is good, but the url still doesnt rewrite to full address (http://sitename/SiteName/ContactUs/Country/UKContactUsPage).
This was not the case when we had episerver 4.62. The user would be redirected to full address. We want to retain this feature as we wouldnt want duplicate URLs for SEO reasons.
How can I achieve this in EPiServer 5. Am I missing any setting here. Is this the default behavior in EPiServer 5 and 6?
This is by default in EPiServer 5 and 6.
Put this piece of code in Global.asax.cs
protected void Application_Start(Object sender, EventArgs e)
EPiServer.Web.InitializationModule.FirstBeginRequest += new EventHandler(InitializationModule_FirstBeginRequest);
void InitializationModule_FirstBeginRequest(object sender, EventArgs e)
EPiServer.Global.UrlRewriteProvider.ConvertedToExternal += new EventHandler<EPiServer.Web.UrlRewriteEventArgs>(UrlRewriteProvider_ConvertedToInternal);
void UrlRewriteProvider_ConvertedToInternal(object sender, EPiServer.Web.UrlRewriteEventArgs e)
//Redirect to real page if permalink if it exists
PageReference pageReference = (PageReference)e.Internal;
PageData page = DataFactory.Instance.GetPage(pageReference);
if (page["PageExternalURL"] != null && ((string)page["PageExternalURL"]) == HttpContext.Current.Request.Url.LocalPath.Replace("/", string.Empty) &&
GetExternalUrl(page.LinkURL) != HttpContext.Current.Request.Url.LocalPath)
HttpContext.Current.Response.Status = "301 Moved Permanently";
HttpContext.Current.Response.AddHeader("Location", Helper.Instance.GetExternalUrl(page.LinkURL) + HttpContext.Current.Request.Url.Query);
public string GetExternalUrl(string internalUrl)
UrlBuilder ub = new EPiServer.UrlBuilder(internalUrl);
Global.UrlRewriteProvider.ConvertToExternal(ub, null, System.Text.Encoding.Default);
Thanks a lot for your time and reply and clarifying my doubt.
In the code snippet, I could only see the method for UrlRewriteProvider_ConvertedToInternal but not the UrlRewriteProvider_ConvertedToExternal. Can you please let me know if the method is correct.
Based on your hint, I tried to write on my own, but couldn't succeed. I get into infinite loop.
Can you please help?
Can you please help?
I have edited the code to fix the typo with Internal/External. I also added a method GetExternalUrl, which I forgot to type here.