We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
  • I have two languages running on http://anyscreensize.com:
    English (http://anyscreensize.com default)
    Dutch (http://anyscreensize.com/nl/)

    Before I updated to MODX 2.2.0-RC3 all was fine (I used the MODX 2.2.0 Beta I think)

    Now If I go to http://anyscreensize.com I get redirected to http://anyscreensize.com/nl/.
    The only way to go to the main English page is to go to http://anyscreensize.com/index and then the page loads fine.

    How can it be that my default web context gets redirected to the dutch context?

    Here my .htaccess (the space in http:// is to have it not render as a link...)
    RewriteEngine On
    RewriteBase /
    
    # Rewrite www.domain.com -> domain.com -- used with SEO Strict URLs plugin
    RewriteCond %{HTTP_HOST} .
    RewriteCond %{HTTP_HOST} !^anyscreensize\.com [NC]
    RewriteRule (.*) http ://anyscreensize.com/$1 [R=301,L] 
    
    # The Friendly URLs part
    # detect language when requesting the root (/)
    RewriteCond %{HTTP:Accept-Language} !^(nl) [NC]
    RewriteRule ^$ nl/ [R=301,L]
     
    # redirect all requests to /de/favicon.ico and /nl/favicon.ico
    # to /favicon.ico
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(nl)/favicon.ico$ favicon.ico [L,QSA]
      
    # redirect all requests to /de/assets* and /nl/assets* to /assets*
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(nl)/assets(.*)$ assets$2 [L,QSA]
     
    # redirect all other requests to /de/* and /nl/*
    # to index.php and set the cultureKey parameter
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(nl)?/?(.*)$ index.php?cultureKey=$1&q=$2 [L,QSA]
    



    • Access controlls for web and dutch context are Load Only

    The web context has the followings settings:

    Here my gateway plugin (OnHandleRequest is checked):
    <?php
    //make sure the plugin does not run on the mgr context (the manager)
                if ( $modx->context->get( 'key' ) != 'mgr') {
                    /**
                    * grab the current context from the request "c" parameter (or context_param_alias from system settings)
                    * the alternative .htaccess friendly URL rewrite rule must be activated
                    */
                    $cntxt_param = $modx->getOption('context_param_alias', null, 'cultureKey');
                    if ( isset( $_REQUEST[$cntxt_param] ) && $_REQUEST[$cntxt_param] != '' ) {
                        switch ( $_REQUEST[$cntxt_param] ) {
     
                            case 'nl':
                            $modx->switchContext('nl');
                            break;
     
                            default:
                            // nothing because web is default
                            break;
     
                        }
                    }
                }
    


    There is nothing in the error log... Anybody know what's up? [ed. note: ThaClown last edited this post 12 years, 3 months ago.]
      MODX Ambassador (NL) | Responsive web design specialist, developer & speaker
      DESIGNfromWITHIN, MPThemes and Any Screen Size
      Follow me on Twitter | Read my blog | My code on GitHub
    • # The Friendly URLs part
      # detect language when requesting the root (/)
      RewriteCond %{HTTP:Accept-Language} !^(nl) [NC]
      RewriteRule ^$ nl/ [R=301,L]
      


      When there's no request uri as defined with ^$ (so allscreensizes.com), it REWRITES that to allscreensizes.com/nl/.

      I think this line:
      RewriteCond %{HTTP:Accept-Language} !^(nl) [NC]

      checks if the accepted language is NOT "nl", so that sounds like the wrong check when you rewrite to /nl/ afterwards. That said - I'm not an expert with mod_rewrite so I can be wrong on that conclusion. [ed. note: markh last edited this post 12 years, 3 months ago.]
        Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

        Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
      • Ok you were right,
        RewriteCond %{HTTP:Accept-Language} !^(nl) [NC]
        

        checks if the code IS NOT nl...

        I changed it to:
        RewriteCond %{HTTP:Accept-Language} !^(en) [NC]
        


        And now it works ok.

        But my question:
        Lets say you have one default language (English) at http://yoursite.com.
        And 3 other languages like Dutch, German and Italian.
        I want these like:
        http://yoursite.com/nl/
        http://yoursite.com/de/
        http://yoursite.com/it/

        How should my .htaccess look?
        [ed. note: ThaClown last edited this post 12 years, 3 months ago.]
          MODX Ambassador (NL) | Responsive web design specialist, developer & speaker
          DESIGNfromWITHIN, MPThemes and Any Screen Size
          Follow me on Twitter | Read my blog | My code on GitHub
        • Ok I am stupid....
          I don't need the
          # The Friendly URLs part
          # detect language when requesting the root (/)
          RewriteCond %{HTTP:Accept-Language} !^(nl) [NC]
          RewriteRule ^$ nl/ [R=301,L]
          


          At all...
            MODX Ambassador (NL) | Responsive web design specialist, developer & speaker
            DESIGNfromWITHIN, MPThemes and Any Screen Size
            Follow me on Twitter | Read my blog | My code on GitHub