O
O
Oleg2018-09-19 11:55:13
Nginx
Oleg, 2018-09-19 11:55:13

How to fix opencart routing from languages ​​in url?

There is a site domain.com
There is a server on nginx Added a
language to the site url so that the domain looks like: domain.com/ru
Now all links look like:
domain.com/ru/cart
domain.com/en/cart
domain.com/ru /login
, etc.
Unfortunately, not all links have CNC installed and where they are not, links like:
domain.com/ru/index.php?route=account/login
The problem is the following: due to RU / EN in the url nginx writes a 404 error. It is nginx, not the site, that processes them.
I need domain.com/RU/index.php links to work and be processed through the site, not nginx.
For example, the link domain.com/RU/asdasidashd gives a 404 error, but this error is generated by the site, not nginx.
And when .php is added at the end - nginx 404 error.
I need this so that the routing works both with CNC and with standard routing, that is, so that nginx does not give its error if you enter domain.com/EN/index.php
I as I understand it, this is because of the nginx config.
He is now like this:

server {
    server_name domain.com;
    root /var/www/domain.com;
    index index.php index.html;

    listen 80;
    listen [::]:80;
    listen 443 default ssl;

    ssl_certificate      /etc/ssl/domain.com.crt;
    ssl_certificate_key  /etc/ssl/domain.com.key;

    # Redirect HTTP to HTTPS
    if ($scheme = http) {
        return 301 https://$server_name$request_uri;
    }

    access_log /var/log/nginx/myopencart_access.log;

    location = /sitemap.xml {
      return 301 /index.php?route=extension/feed/google_sitemap;
    }

    location = /googlebase.xml {
      return 301 /index.php?route=extension/feed/google_base;
    }

    location /image/data {
        autoindex on;
    }
    location /admin {
        index index.php;
    }
    location / {
        try_files $uri @opencart;
    }
    location @opencart {
        rewrite ^/(.+)$ /index.php?_route_=$1 last;
    }

    # Make sure files with the following extensions do not get loaded by nginx because nginx would display the source code, and these files can contain PASSWORDS!
    location ~* \.(engine|inc|info|install|make|module|profile|test|po|sh|.*sql|theme|tpl(\.php)?|xtmpl)$|^(\..*|Entries.*|Repository|Root|Tag|Template)$|\.php_ {
        deny all;
    }
    # Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac).
    location ~ /\. {
        deny all;
        access_log off;
        log_not_found off;
    }
    location ~*  \.(jpg|jpeg|png|gif|css|js|ico|json|xml|woff|woff2)$ {
        expires max;
        add_header Cache-Control "max-age=2592000";
        access_log off;
    }
    location ~ \.php$ {
                try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_intercept_errors off;
        fastcgi_buffer_size 16k;
        fastcgi_buffers 4 16k;
    }
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question