Share This
 
All Posts  /  Kentico Development Tips  /  May 01, 2016 

Kentico 301 URL Redirect Module: Quick Fix To Allow External Redirects

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));
}
Show More
Share This
 
Comments
Blog post currently doesn't have any comments.
*
 Security code
*
ADD COMMENT
Social Buzz

Get in Touch

Contact

Contact
t: 973.539.5255
f: 973.917.4730

Visit

Visit
715 Main Street
Boonton, NJ 07005

Locations

Locations
Boonton
Dallas
Jersey City
Boulder

Send Us a Message




 Security code