We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 16702 ☆ A M B ☆
    • 536 Posts
    Hello guys,


    а few days ago with my colleague, We thought over how to create dynamic 404 page (different languages).
    What we do?

    1. create a snippet with some name (example "404redirect"):
    <?php
    $niz = $_SERVER['REQUEST_URI'];
    $ogranichenie = substr($niz, 1, 3);
    if ($ogranichenie == "en/") //the language prefix
    {
        echo  $modx->sendRedirect('http://www.domain.bg/en/404', 0, 'REDIRECT_HEADER', 'HTTP/1.1 301 Moved Permanently');
    }
    else
    {
        echo "";
    }
    ?>

    where " /en " is the other language and "’http://www.domain.bg/en/404" full path to our second 404 page (with another language or content)
    ---> put the snippet in the your 404 page.

    that is all

    What do you think about it
      palma non sine pulvere
      • 9207 ☆ A M B ☆
      • 2,475 Posts
      Don’t send a 301 when you mean a 404. The 404 page sends an error to anyone (or anything) trying to access the page, e.g. Google won’t index a page that sends a 404 header.

      You could put a Snippet on your 404 page (choose which page acts as your 404 page in your site config), and then print out the language specific text using a series of if/elseif statements or switch block (i.e. a select/case), but this would limit the response only to the page’s CONTENT, and not to its title, description, etc.

      A better alternative to this is create a series of 404 pages for each language your site supports, then create a plugin that fires on the OnPageNotFound event with a similar if/elseif or switch block:

      $niz = $_SERVER['REQUEST_URI'];
      $ogranichenie = substr($niz, 1, 3);
      switch ($ogranichenie) {
          case 'en':
              $modx->sendForward( 123, 'HTTP/1.0 404 Not Found');  // where 123 is the page_id of the English 404 page
          	exit();
              break;
          case 'sp':
              $modx->sendForward( 243, 'HTTP/1.0 404 Not Found');  // where 243 is the page_id of the Spanish 404 page
          	exit();
              break;
          default:
              $modx->sendForward( 333, 'HTTP/1.0 404 Not Found');  // where 333 is the page_id of the catch-all 404 page
              exit();
              break;
      }
      


      See the MODx API: http://wiki.modxcms.com/index.php/API:sendForward

      Alternatively, you could use one of the multi-lingual solutions that rely on xml-style tags to delineate blocks of language-specific text, but I think the above solution is easier.
        • 16702 ☆ A M B ☆
        • 536 Posts
        Hello Everett,

        i test your code but for me is not work....the page is blank...maybe i have somewhere error...
        :)


        Kristalin
          palma non sine pulvere
          • 36678
          • 152 Posts
          The problem is small...

          case ’en/’:

          and etc. I used a combination of both solutions.
            Multylingo 1.0 alpha (snippet + plugin) - For creation a full-featured multilingual site with MODx Evo
            My sites:
            Мисли, интересни мисли
            • 16702 ☆ A M B ☆
            • 536 Posts
            nope,

            when i use Everett script output is:

            HTTP 500 - Internal Server Error
            The server responded with an error page.
              palma non sine pulvere
              • 9207 ☆ A M B ☆
              • 2,475 Posts
              You’ll have to test this slowly. First make a plugin that executes on the correct event, then print out the URL being requested, eg print $_GET[’q’]

              The code above isn’t tested, I just wanted to show you the technique.
                • 49359
                • 16 Posts
                I used BABEL and to make nesolko PAGE 404, I created a context in each type of setting

                Key: error_page
                Dictionary: site
                Meaning: " context 404 page id"


                And in general settings key: error_page left empty