Provide 404 documentation with NGINX relative to the current path

I have the following server blocks:

server {
listen 80;
server_name petpal. co.il;
root /usr/share/nginx/petpal;
index index.php;
location / {
try_files $uri $uri/ @extensionless-php;< br /> }
location @extensionless-php {
rewrite ^(.*)$$1.php last;
}
location ~ \.php${
try_files $uri /notfound;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}< br />}

What changes do I need to make to make the 404 document display according to the user’s current directory, for example, in the directory “/en” it will display “/en/notfound” and the directory “/”. Show “/notfound”?

Maybe an if will work?

set $lang "";
if ($uri ~ "^/en/") {set $lang "en/"; }< br />try_files $uri /${lang}notfound;

Or, if you want a more general rule:

set $lang "" ;
if ($uri ~ "^/([az][az])/)") {set $lang "$1"; }
try_files $uri /${lang}notfound;

I have the following server blocks:

server {
listen 80;
server_name petpal.co.il;
root /usr/share/nginx/petpal;
index index.php;
location / {
try_files $uri $uri/ @extensionless-php ;
}
location @extensionless-php {
rewrite ^(.*)$$1.php last;
}
location ~ \.php${
try_files $uri /notfound;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}

What changes do I need to make to display the 404 document according to the user’s current directory, for example, "/en/notfound" and directory "/" are displayed in the directory "/en" It will display "/notfo und"?

Maybe an if will work?

set $lang "";
if ($uri ~ "^/en/") {set $lang "en/"; }< br />try_files $uri /${lang}notfound;

Or, if you want a more general rule:

set $lang "" ;
if ($uri ~ "^/([az][az])/)") {set $lang "$1"; }
try_files $uri /${lang}notfound;

Leave a Comment

Your email address will not be published.