Hi, I have an Umbraco installation with multiple sites, but when I want to control the 404 error page then I run into a problem, because I cannot make it differ betweeen the two sites. The 404 error id in the umbracoSettings.config file is just for one id and not multiple. How can I solve this?
If they have the same culture, then what Paul suggested should be what you need to get everything working properly. The "culture" attribute is there to handle multi-language sites so having, for example, four sites that are English each with their own custom 404 page won't work until you follow the steps in the link Paul posted above.
I removed everything from <errors> to </errors> in umbracoSetting.config and followed the instructions here to implement my custom class and didn't have any issues.
Following the same instructions that Donald and Paul referenced, I came up with the following class combined with uComponents/uQuery to make my life easier.
public class LocalisedDirectory404Handler : INotFoundHandler
{
private int redirectId;
public bool Execute(string url)
{
var localeSelectorRegex = new Regex(@"(\w{2})/");
var matches = localeSelectorRegex.Match(url);
if (matches.Success)
{
var locale = matches.Groups[1].Value;
string notFoundXPath = "//homepage[@isDoc and @urlName = '{0}']/ErrorPageGroup/Content[@isDoc and @urlName = '{1}']";
var notFoundQuery = String.Format(notFoundXPath, locale, "page-not-found");
var result = uQuery.GetNodesByXPath(notFoundQuery);
if (result.Count > 0)
{
redirectId = result.First().Id;
return true;
}
}
return false;
}
public bool CacheUrl
{
get { return false; }
}
public int redirectID
{
get { return redirectId; }
}
}
Your XPath for the notFoundXPath will almost certainly be different, as will your regex to find the site root base url (in my case, en, fr, de, etc). This might help someone to extend, though :)
I found that the problem with the INotFoundHandler was that the url parameter was only a relative url, so I still could not determine the domain without looking in the HttpContext.
I ended up adding the httpError element in my web.config as follows
404 with multiple sites?
Hi, I have an Umbraco installation with multiple sites, but when I want to control the 404 error page then I run into a problem, because I cannot make it differ betweeen the two sites. The 404 error id in the umbracoSettings.config file is just for one id and not multiple. How can I solve this?
Thanks.
Scott
Scott -
If your sites have different cultures you can set a 404 for each in umbracoSettings.config like this:
<errorPage culture="en-US">200</errorPage>
-Paul
oops...also wanted to point you to this Wiki-entry detailing how to create a 404-handler for multiple sites even if they are of the same culture:
http://our.umbraco.org/wiki/how-tos/how-to-implement-your-own-404-handler
-Paul
Hey Paul,
Thanks, but they have all the same culture. I might need to write my own handler then.
Scott
Scott,
If they have the same culture, then what Paul suggested should be what you need to get everything working properly. The "culture" attribute is there to handle multi-language sites so having, for example, four sites that are English each with their own custom 404 page won't work until you follow the steps in the link Paul posted above.
I removed everything from <errors> to </errors> in umbracoSetting.config and followed the instructions here to implement my custom class and didn't have any issues.
Hope this helps.
--
Donald
Following the same instructions that Donald and Paul referenced, I came up with the following class combined with uComponents/uQuery to make my life easier.
Your XPath for the notFoundXPath will almost certainly be different, as will your regex to find the site root base url (in my case, en, fr, de, etc). This might help someone to extend, though :)
I found that the problem with the INotFoundHandler was that the url parameter was only a relative url, so I still could not determine the domain without looking in the HttpContext.
I ended up adding the httpError element in my web.config as follows
Then, under each site / domain, you just need a page named "Page Not Found". You can then make this editable.
Hi,
Maybe you can use this package :
https://our.umbraco.org/projects/backoffice-extensions/umbraco-page-not-found-manager/
Dave
is working on a reply...