Answer the question
In order to leave comments, you need to log in
How to fix a 404 error for a bilingual site in NGINX?
Hello.
When migrating a site (MODx engine) from Apache to NGINX, I encountered the fact that the URLs for the English version of the site give a 404 error, while everything works for the Russian one.
URLs for the Russian version look like https://site.com/page/ (server response code 200)
URLs for the English version look like https://site.com/en/page/ (server response code 400)
How to set up URL generation for the English version in the NGINX virthost configs?
Wirthhost config
server {
listen 80;
server_name example.com www.example.com;
root /home/sites/example.com;
index index.php;
client_max_body_size 30M;
location / {
root /home/sites/example.com;
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php?q=$1 last;
}
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_pass unix:/run/php/php7.2-fpm.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;
}
location ~ /\.ht {
deny all;
}
}
Answer the question
In order to leave comments, you need to log in
location / {
rewrite ^/(en|ru)/?(.*)$ /index.php?cultureKey=$1&q=/$2 last;
try_files $uri /index.php?q=$request_uri;
}
index.php
is implied not only in the root, but also in subdirectories, replace $uri
with $uri $uri/
.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question