Answer the question
In order to leave comments, you need to log in
How to rewrite rules for NGINX?
There are the following rules in .htaccess, now the site needs to be transferred to a server with NGINX:
# The Friendly URLs part
# redirect all requests to /ru/favicon.ico
# to /favicon.ico
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(sr|ru)favicon.ico$ favicon.ico [L,QSA]
# redirect all requests to /en/assets* and /ru/assets* to /assets*
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(sr|ru)/assets(.*)$ assets$2 [L,QSA]
# redirect all other requests to /ru/*
# to index.php and set the cultureKey parameter
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(sr|ru)?/?(.*)$ index.php?cultureKey=$1&q=$2 [L,QSA]
Answer the question
In order to leave comments, you need to log in
I write offhand, just to show the idea, I am not responsible for the correctness of the syntax.
HTTP Redirect with 301 response code (the rest are similar)
location /en/favicon.ico {
return 301/favicon.ico;
}
Translation to another location (it must be created, ie location /assets/ must exist).
Sequentially pass to other locations, if not found then return 403.
location /ru/ {
rewrite ^(/ru)/assets/(.*)$ /assets/$2 break;
rewrite ^(/ru)/favicon.ico$ /favicon.ico break;
rewrite ^(/en)/assets/(.*)$ $1/assets/$2 break;
rewrite ^(/en)/(.*)$ /index.php break;
return 403;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question