Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Scott Hugh Alexandar Petersen 349 posts 164 karma points
    Mar 12, 2010 @ 20:28
    Scott Hugh Alexandar Petersen
    0

    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

  • Paul Sterling 718 posts 1534 karma points MVP 9x admin c-trib
    Mar 12, 2010 @ 20:36
    Paul Sterling
    0

    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

  • Paul Sterling 718 posts 1534 karma points MVP 9x admin c-trib
    Mar 12, 2010 @ 20:38
    Paul Sterling
    2

    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

  • Scott Hugh Alexandar Petersen 349 posts 164 karma points
    Mar 15, 2010 @ 11:40
    Scott Hugh Alexandar Petersen
    0

    Hey Paul,

    Thanks, but they have all the same culture. I might need to write my own handler then.

    Scott

  • Donald St. Martin 83 posts 128 karma points
    Mar 15, 2010 @ 14:59
    Donald St. Martin
    0

    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

     

  • Kevin Blake 23 posts 45 karma points
    Sep 06, 2011 @ 14:12
    Kevin Blake
    0

    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 :)

  • Andrew Vennells 16 posts 101 karma points
    Nov 16, 2016 @ 05:42
    Andrew Vennells
    0

    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

    <system.webServer>
        <httpErrors errorMode="Custom">
            <remove statusCode="404" />
            <error statusCode="404" path="/page-not-found" responseMode="ExecuteURL" />
        </httpErrors>
    </system.webServer>
    

    Then, under each site / domain, you just need a page named "Page Not Found". You can then make this editable.

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Nov 16, 2016 @ 06:39
Please Sign in or register to post replies

Write your reply to:

Draft