We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28120
    • 380 Posts
    I’ve got to build a multi-language Revolution site for 5 European countries and, after some deliberation, I’ve decided to go with one Web context and sub-folders rather than one Context per language.

    I’ve performed the following so far


    • Set ‘use_alias_path’ to true
    • Created a couple of containers ‘en’ and ‘de’ with some pages underneath
    • Set Web context ‘site_start’ to point to the ‘en’ container

    All seems to work well except


    • When I browse ‘mydomain.com’ without specifying a country code I’d like it to rewrite as ‘mydomain.com/en/’ instead of sticking on ‘mydomain.com’ - it show the content from container ‘en’ ok
    • When I browse ‘mydomain.com/en’ or ‘mydomain.com/en/’ it currently rewrites as ‘mydomain.com’ which is not what I want. It’s showing the content ok from the container ‘en’ but rewriting the url. If I browse ‘mydomain.com/en/a-sub-page.html’ it sticks on that url ok.

    I’ve tried a few options in .htaccess without success. Also I don’t want to break anything in terms of folders such as /assets.

    Any pointers appreciated.

    Mark
      • 4172
      • 5,888 Posts
      what you can do is:

      create a snippet ’sendRedirect’ with this code:
      <?php
      return $modx->sendRedirect($modx->makeUrl($docid));


      create a new home-resource for site-start with this snippet-tag:
      [[sendRedirect? &docid=`yourStartResourceID`]]

      and point the system-setting site-start to this resource.
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 28120
        • 380 Posts
        Thanks

        Will Google treat this as a friendly redirect?
          • 28120
          • 380 Posts
          sendRedirect as described above redirects as a 302 which I’m a bit worried about from an SEO perspective.

          Poking around in the ’redirector’ package I’ve found that preceding the redirect with a header declaration fixes it

          header('HTTP/1.1 301 Moved Permanently');
          return $modx->sendRedirect($modx->makeUrl($docid));
          


          Not entirely sure how/why this works because I can’t see how the $modx->sendRedirect($modx->makeUrl($docid)) command knows I’ve declared the header.

          Anyhow it’s a working solution which I’m happy about. Still have a nagging feeling I should be doing this stuff in .htaccess ...
            • 22303 MODX Staff
            • 10,725 Posts
            The modX::sendRedirect method takes a parameter to specify the header sent in the response, e.g.

            <?php
            return $modx->sendRedirect($modx->makeUrl($docid, '', '', 'full'), array(
                'responseCode' => 'HTTP/1.1 301 Moved Permanently'
            ));


            Also note that you should never send relative URLs to sendRedirect() — always use complete URLs or the redirects will fail in many versions of IE.
              • 28120
              • 380 Posts
              Great - thanks for this