I have a parent page with many children pages. Some of those children were deleted and I would like to redirect those broken pages that currently go to 404 page back to the parent page.
I am currently using this. Is there a way to get something like home/products/wire to go back to home/products if wire page does not exist?
public override void Process(HttpRequestArgs args)
{
if (Sitecore.Context.Database == null)
return;
if (string.Equals(disallowedDatabases, Sitecore.Context.Database.Name, StringComparison.InvariantCultureIgnoreCase))
return;
if (string.Equals(disallowedSites, Sitecore.Context.Site.SiteInfo.Name, StringComparison.InvariantCultureIgnoreCase))
return;
// retain 500 response if previously set
if (HttpContext.Current.Response.StatusCode >= 500 && HttpContext.Current.Error != null)
{
Log.Error("Custom Error : Internal Server Error : " + HttpContext.Current.Error.InnerException, this);
return;
}
// return if request not equal to value set in ItemNotFoundUrl, i.e. successful page
if (string.Equals(args.Context.Request.Url.LocalPath, Sitecore.Configuration.Settings.ItemNotFoundUrl, StringComparison.InvariantCultureIgnoreCase))
{
HttpContext.Current.Response.TrySkipIisCustomErrors = true;
HttpContext.Current.Response.StatusCode = (int)HttpStatusCode.NotFound;
HttpContext.Current.Response.StatusDescription = "Page not found";
Log.Error("Custom Error : Item Not Found :" + args.Context.Request.RawUrl, this);
}
else if (string.Equals(args.Context.Request.Url.LocalPath, "/500", StringComparison.InvariantCultureIgnoreCase))
{
HttpContext.Current.Response.TrySkipIisCustomErrors = true;
HttpContext.Current.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
HttpContext.Current.Response.StatusDescription = "Internal server Error";
//Log.Error("Custom Error : Item Not Found :" + args.Context.Request.RawUrl, this);
}
}