Insights

Kentico URL Redirect Module Tweak

Kentico provides an easy to use redirection module that allows you to have all of your redirects in one place. However, the module does not allow you to redirect to external links. In this post I provide a quick tweak to the redirect module code that will allow you to enter the full path to redirect to external sites.

Kentico provides an easy to use redirection module that allows you to have all of your redirects in one place. However, the module does not allow you to redirect to external links. In this post I provide a quick tweak to the redirect module code that will allow you to enter the full path to redirect to external sites.

Open the RedirectionMethods.cs file found in App_Code > CMS_Modules > URLRedirection

Starting on line 16, replace the code block:


if (ValidationHelper.GetString(ds.Tables[0].Rows[0]["RedirectionType"], "301") == "301")
{
    URLHelper.RedirectPermanent(URLHelper.ResolveUrl("~" + ValidationHelper.GetString(ds.Tables[0].Rows[0]["RedirectionTargetURL"], "/")), SiteInfoProvider.GetSiteName(site));
}

With the following:


if (ValidationHelper.GetString(ds.Tables[0].Rows[0]["RedirectionType"], "301") == "301")
{
     string redirect_url = ValidationHelper.GetString(ds.Tables[0].Rows[0]["RedirectionTargetURL"], "/");
     if(!(redirect_url.Contains("http://") || redirect_url.Contains("https://"))){
          redirect_url = "~" + redirect_url;
     }
     URLHelper.RedirectPermanent(URLHelper.ResolveUrl(redirect_url), SiteInfoProvider.GetSiteName(site));
}
Let's Talk

Get in Touch

Ready to start a project? Need support? Or, have a question? Connect with us!