We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 40362
    • 5 Posts
    Hi as said in the title.
    I have nginx set up and it works with babel in all but one way.....

    when I load http://mydomainname.com the server first respond with 404 and after that sends the page http://mydomainname.com

    when I load http://mydomainname.de it redirects to http://mydomainname.com/de/ and shows the page without first sending 404.

    This messes with adds and other things as they tend to see the site as dead.

    writing http://mydomainname.com/index.php it works fine.

    This is my nginx config.

    include /etc/nginx/include/ssl;
    
    server {
        listen 0.0.0.0:80;
        root /var/www/mydomainname;
        index index.php;
        include /etc/nginx/include/php;
    }
    server {
        listen 80;
        server_name se.mydomainname.com;
        rewrite ^(.*)$ $scheme://mydomainname.com;
    }
    
    server {
        listen 80;
        listen 443 ssl;
        server_name www.mydomainname.at mydomainname.at www.mydomainname.de mydomainname.de;
        rewrite ^(.*)$ $scheme://mydomainname.com/de$1;
    }
    
    server {
        listen 80;
        listen 443 ssl;
        server_name www.mydomainname.no mydomainname.no;
        rewrite ^(.*)$ $scheme://mydomainname.com/no$1;
    }
    
    server {
        listen 80;
        listen 443 ssl;
        server_name www.mydomainname.fi mydomainname.fi;
        rewrite ^(.*)$ $scheme://mydomainname.com/fi$1;
    }
    
    server {
        listen 80;
        server_name www.mydomainname.com;
        rewrite ^(.*)$ $scheme://mydomainname.com;
    }
    
    server {
        listen 443 ssl;
        server_name mydomainname.com;
        root /var/www/mydomainname;
        index index.php;
    
        #include /etc/nginx/include/ssl;
        include /etc/nginx/include/php;
    
        client_max_body_size 60M;
    
        location = /favicon.ico     { return 204; }
        location = /favicon.png     { }
    
        location ~* \.(jpg|jpeg|gif|png|js|ico|html)$ {
          access_log off;
          expires 1d;
        }
    
       ## Friendly urls
        location / {
            if (!-e $request_filename) {
                rewrite ^/(.*)$ /index.php?q=$1 last;
            }
        }
            ## Babel fix
            if (!-d $request_filename){
                    set $rule_0 1$rule_0;
            }
            if (!-f $request_filename){
                    set $rule_0 2$rule_0;
            }
            if ($rule_0 = "21"){
                    rewrite ^/(sv|en|fi|de|no)/favicon.ico$ /favicon.ico last;
            }
            if (!-d $request_filename){
                    set $rule_1 1$rule_1;
            }
            if (!-f $request_filename){
                    set $rule_1 2$rule_1;
            }
            if ($rule_1 = "21"){
                    rewrite ^/(sv|en|fi|de|no)/assets(.*)$ /assets$2 last;
            }
            if (!-f $request_filename){
                    set $rule_2 1$rule_2;
            }
            if (!-d $request_filename){
                    set $rule_2 2$rule_2;
            }
            if ($rule_2 = "21"){
                    rewrite ^/(sv|en|fi|de|no)?/?(.*)$ /index.php?cultureKey=$1&q=$2 last;
            }
    
        location ~ \.php$ {
            try_files $uri =404;
            fastcgi_param HTTPS on;
            fastcgi_pass   unix:/var/run/nginx/php-fastcgi.sock;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include fastcgi_params;
            fastcgi_ignore_client_abort on;
            fastcgi_param  SERVER_NAME $http_host;
    
            fastcgi_buffer_size 128k;
            fastcgi_buffers 256 16k;
            fastcgi_busy_buffers_size 256k;
            fastcgi_temp_file_write_size 256k;
            fastcgi_read_timeout 240;
        }
    
        location ~ /\.ht {
            deny  all;
        }
    
    }
    
    server {
        listen 80;
        server_name mydomainname.com;
        root /var/www/mydomainname;
        index index.php;
    
        include /etc/nginx/include/php;
    
        client_max_body_size 160M;
        location / {
            root /var/www/mydomainname;
            if (!-e $request_filename) {
                rewrite ^/(.*)$ /index.php?q=$1 last;
            }
        }
        
        location = /favicon.ico     { return 204; }
        location = /favicon.png     { }
    
        location ~* \.(jpg|jpeg|gif|png|js|ico|html)$ {
          access_log off;
          expires 1d;
        }
    
    	## Babel fix
    	if (!-d $request_filename){
    		set $rule_0 1$rule_0;
    	}
    	if (!-f $request_filename){
    		set $rule_0 2$rule_0;
    	}
    	if ($rule_0 = "21"){
    		rewrite ^/(sv|en|fi|de|no)/favicon.ico$ /favicon.ico last;
    	}
    	if (!-d $request_filename){
    		set $rule_1 1$rule_1;
    	}
    	if (!-f $request_filename){
    		set $rule_1 2$rule_1;
    	}
    	if ($rule_1 = "21"){
    		rewrite ^/(sv|en|fi|de|no)/assets(.*)$ /assets$2 last;
    	}
    	if (!-f $request_filename){
    		set $rule_2 1$rule_2;
    	}
    	if (!-d $request_filename){
    		set $rule_2 2$rule_2;
    	}
    	if ($rule_2 = "21"){
    		rewrite ^/(sv|en|fi|de|no)?/?(.*)$ /index.php?cultureKey=$1&q=$2 last;
    	}
    
    
        location ~ \.php$ {
            try_files $uri /index.php =404;
            #fastcgi_param HTTPS on;
            fastcgi_pass   unix:/var/run/nginx/php-fastcgi.sock;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include fastcgi_params;
            fastcgi_ignore_client_abort on;
            fastcgi_param  SERVER_NAME $http_host;
    
    
            fastcgi_buffer_size 128k;
            fastcgi_buffers 256 16k;
            fastcgi_busy_buffers_size 256k;
            fastcgi_temp_file_write_size 256k;
            fastcgi_read_timeout 240;
        }
    
        location ~ /\.ht {
            deny  all;
        }
    }
    
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      You might do better using the plugin that does not require server rewrites. https://gist.github.com/gadamiak/3812853
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 40362
        • 5 Posts
        Tried that one but did not quite get it to work. I probably did something wrong.... smiley
        What I did was replaced my "gateway" plugin code with the one you linked to (with your fix).
        And I removed all the rewrite roles from my nginx config but that resulted in 500 errors everywhere :/
        I'm sure that I'm missing something obvious but cant figure it out by my self.

        What am I missing?

        this was my original gateway code

        if($modx->context->get('key') != "mgr"){
                /* grab the current langauge from the cultureKey request var */
                switch ($_REQUEST['cultureKey']) {
                    case 'en':
                        /* switch the context */
                        $modx->switchContext('English');
                        break;
                    case 'fi':
                        /* switch the context */
                        $modx->switchContext('Finnish');
                        break;
                    case 'no':
                        /* switch the context */
                        $modx->switchContext('Norway');
                        break;
                    case 'de':
                        /* switch the context */
                        $modx->switchContext('German');
                        break;
                    case 'at':
                        /* switch the context */
                        $modx->switchContext('German');
                        break;
                    default:
                        /* Set the default context here (Swedish) */
                        $modx->switchContext('web');
                        break;
                }
                /* unset GET var to avoid
                 * appending cultureKey=xy to URLs by other components */
                unset($_GET['cultureKey']);
            }
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          Replacing the gateway code will work. The nginx config file was broken when you edited it. Go over it again and make sure it's back to its original state.
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 40362
            • 5 Posts
            I'm probably missing something obvious but I'm not getting it to work. What steps do I need to take?

            I set up my context like said in the code comments.

            Context web
            base_url: /
            Culture Key: sv
            site_url: http://mydomainname.com

            Context Norway
            base_url: /
            Culture Key: no
            site_url: http://mydomainname.com/no/

            Context German
            base_url: /
            Culture Key: de
            site_url: http://mydomainname.com/de/

            I inserted the new code with your fix in the gatway.

            The result is that I'm getting blank pages. The error log in modx says
            [2014-08-21 23:32:55] (ERROR @ /index.php) Could not prepare context: en
            [2014-08-21 23:33:11] (ERROR @ /index.php) Could not prepare context: en
            [2014-08-21 23:34:06] (ERROR @ /index.php) Could not prepare context: sv
            [2014-08-21 23:34:35] (ERROR @ /index.php) Could not prepare context: sv
            [2014-08-21 23:34:49] (ERROR @ /index.php) Could not prepare context: no
            [2014-08-21 23:34:49] (ERROR @ /index.php) Query is empty
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              I used this tutorial, with the exception of the part about the .htaccess file. In fact the gateway plugin I use is from the comments to this article.

              http://www.multilingual-modx.com/blog/2011/seo-friendly-multilingual-websites-with-modx-and-babel.html

              Just for your information - I don't use Babel and contexts any more, I use MIGXMultilang.
                Studying MODX in the desert - http://sottwell.com
                Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                Join the Slack Community - http://modx.org