Copied to clipboard

Flag this post as spam?

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


  • Bjorn Van Hoeymissen 27 posts 48 karma points
    Jul 14, 2010 @ 14:48
    Bjorn Van Hoeymissen
    0

    404 handling on multilingual site

    Hi guys,

    normally we just use the <error404> in umbracoSettings.config to point to a fixed nodeId for a custom error page. However currently we're needing different custom error pages for different languages. The <errorPage> entries don't seem to be quite as cooperative and the only one that works is the "default" one. Others cultures get ignored?

    Our setup:
    <errorPage culture="default">1</errorPage>
    <errorPage culture="nl-NL">1245</errorPage>

    We've also tried adding the <error404> tags around these (as suggested in some other posts), but that doesn't change anything.

    In Umbraco we have two sites (SiteSections), each with their own language sections. To every language section we have a culture defined through manage hostnames. If I check for the availability of the culture, all is good and dictionary items also work a charm.

    In web.config there are no custom error handlers defined that might overrule the umbracoSettings.config.

    Any ideas?

  • wolulcmit 357 posts 693 karma points
    Jul 14, 2010 @ 14:52
    wolulcmit
    0

    *bump, I'd be curious to know the answer for this one too.

  • Thomas Höhler 1237 posts 1709 karma points MVP
    Jul 14, 2010 @ 15:19
    Thomas Höhler
    1

    I wrote my own 404 handler where I react on the language and position in the tree and return true if I found a node which handles the specific node/language. Definitions on what to chosse are stored in an xml config file.

  • wolulcmit 357 posts 693 karma points
    Jul 14, 2010 @ 15:26
    wolulcmit
    0

    @Thomas, care to share those mad skills? any source we can sneek a look at anywhere?

  • Thomas Höhler 1237 posts 1709 karma points MVP
    Jul 14, 2010 @ 15:27
    Thomas Höhler
    2

    Here is a simple peace of code which demonstrates the usage. You can also react on the Browser language settings or all other HTTP headers:

    Snippet

    using System;
    using System.Web;
    using umbraco.BusinessLogic;
    using umbraco.interfaces;

    namespace MyLibrary.Handler
    {
        public class NotFoundTestHandlerINotFoundHandler
        {

            private bool cacheUrl;

            private int redirectId;


            public bool Execute(string url)
            {
                try
                {
                    var server = HttpContext.Current.Request.ServerVariables["SERVER_NAME"];
                    var referrer = "";
                    if (HttpContext.Current.Request.UrlReferrer != null)
                        referrer = HttpContext.Current.Request.UrlReferrer.ToString();

                    if (server == null)
                        server = "";
                    if (url == null)
                        url = "";

                    var completeUrl = server + "/" + url;
                    Log.Add(LogTypes.NotFound, 0, "MyNotFoundHandler: " + completeUrl + " || Referrer: " + referrer);


                    if (completeUrl.StartsWith("www.mydomain1.com/en"))
                    {
                        redirectId = GetMyEnNodeID;
                        return true;
                    }
                    if (completeUrl.StartsWith("www.mydomain1.com/de"))
                    {
                        redirectId = GetMyDeNodeId();
                        return true;
                    }
                    return false;
                }
                catch (Exception ex)
                {
                    Log.Add(LogTypes.Error, 0,
                            "MyLibrary.Handler.NotFoundTestHandler: " + ex.Message + "\n\n" + ex.StackTrace);
                    return false;
                }
            }

            public bool CacheUrl
            {
                get { return cacheUrl; }
            }

            public int redirectID
            {
                get { return redirectId; }
            }
        }
    }

    hth, Thomas

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Jul 14, 2010 @ 15:38
    Lee Kelleher
    2

    Hi Bjorn,

    The structure of the error pages should be like this...

    <errors>
        <error404>
            <errorPage culture="default">1</errorPage>
            <errorPage culture="nl-NL">1245</errorPage>
        </error404>
    </errors>

    Just checking, is that what you had?

    A NotFoundHandler, like Thomas's one, is the way I'd go about doing it.  But I've been using a version from a code snippet I found in an old Umbraco book:

    http://umbraco.org/documentation/books/not-found-handlers/creating-a-custom-not-found-handler

    It lets you control the 404 page within Umbraco, via a content picker data-type.

    Good luck, Lee.

  • Bjorn Van Hoeymissen 27 posts 48 karma points
    Jul 14, 2010 @ 17:09
    Bjorn Van Hoeymissen
    0

    Hi Lee,

    that's exactly what we have, yes. Even though we've got the hostname set up to Dutch (Netherlands), it keeps going to whatever pageId we enter in the 'default' entry. Very curious.

    Thomas: thanks for your insights and code. Might have to look into implementing something similar in future projects.

  • Seth Niemuth 275 posts 397 karma points
    Feb 09, 2011 @ 16:28
    Seth Niemuth
    0

    Bjorn, any solution as to why it is just going to the default entry?

  • Bjorn Van Hoeymissen 27 posts 48 karma points
    Feb 09, 2011 @ 16:56
    Bjorn Van Hoeymissen
    0

    Seth,

    we've had no luck getting this to work as it should out of the box. Ultimately resulted to some custom programming as suggested above.

    Sorry I have no better news for you.

Please Sign in or register to post replies

Write your reply to:

Draft