page not found url based on different channels

Yowaraj Chhetri asked on October 11, 2018 08:04

Hi Kentico team,

I have three different channels(sub directory/content tree) under one root(master page) having sub master page each. Whenever user in channel 1 types wrong url it should take them to 404 custom error page of channel 1 content tree. And for user tying wrong url in Channel 2, it should take them to 404 custom error page of channel 2 content tree and so on. How do we achieve this? I set up 404 error page in setting->content(Page not found URL) but it is only for global. I am looking for channel (or) Sub Content tree specific, so that site header of individual channel remains the same.

Thanks in advance.

Recent Answers


Arun Kumar answered on October 11, 2018 08:30 (last edited on October 11, 2018 08:32)

You can achieve that simply using some JS code. For that you need to create separate 404 pages for each sub directory. So you have one 404 page at root level and separate 404 page for each sub directory. Then simply add Javascript web part to your sub directory 404 page with below JS code

var currentPath=window.location.pathname;
var subDirPath=currentPath.split('/')[1];
var errorPage=currentPath.split('/')[2];
if(subDirPath.indexOf("ndx")>-1 && errorPage !="404") //404 is error page name
{
  window.location.href="/"+subDirPath+"/404";
}

Another option that I can think of is to use linked 404 error page for all sub channels and use page aliases for individual sub channel under 404 page.

0 votesVote for this answer Mark as a Correct answer

Yowaraj Chhetri answered on October 12, 2018 01:56

Hi Arun, I tried both the method but it did not work. For the 1st method: I created individual 404 pages as stated one for root and other for sub directory. And in the setting-Content(Page not found URL), I gave "/404.aspx". I included java script but it did not make sense, because path can be of any number.

For the 2nd method: I created linked 404 pages as stated and set the setting->Content(Page not found URL) to /404.aspx. And also created page aliase to /404.aspx in individual sub directory 404 pages.

0 votesVote for this answer Mark as a Correct answer

Arun Kumar answered on October 12, 2018 06:32

Where you included javascript? It should be on root 404 page. So whenever it lands to root 404 page you just need to check current path and redirect based on that.

For Alias part you need to set page alias in linked 404 pages as

/subdirectoryname/404.aspx
1 votesVote for this answer Mark as a Correct answer

Yowaraj Chhetri answered on October 15, 2018 00:58

Hi Arun, Still both the methods does not work. First method is not dynamic with url. The error page (404) can occur from any parts of the url (eg, domainname/subdir/anything, domainname/subdir/anotherdir/anything, domainname/anything) Second method still does not work, I have done as stated and please see the pics below if I have done anything wrong.

Setting Setting Page

404-1 Error (404) page in root level

404-2 Linked page(404) in sub directory and setting the alias path

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.