Answer the question
In order to leave comments, you need to log in
How to write rewrite rules for nginx that will add a slash at the end of the link?
Hello, I am turning to you after Google, help me create rewrite rules for nginx, which will add a slash at the end of the link as follows
site.ru/controller => site.ru/controller/
site.ru/controller?params=2 => site. ru/controller/?params=2
And at the same time do not rewrite files with the extension jpg png css jss..etc
I know that in htaccess it would be like this
RewriteCond %{REQUEST_URI} !/$
RewriteCond %{REQUEST_URI} !\.
RewriteRule ^(.*) %{REQUEST_URI}/ [R=301,L]
Answer the question
In order to leave comments, you need to log in
I do something like this:
location / {
rewrite ^([^.\?]*[^/])$ $1/ permanent;
try_files $uri @clean_url;
}
# Исключение по расширению файлов
RewriteCond %{REQUEST_URI} !(jpg|png|gif|ico)
# Дальше всё по старому
RewriteCond %{REQUEST_URI} !/$
RewriteCond %{REQUEST_URI} !\.
RewriteRule ^(.*) %{REQUEST_URI}/ [R=301,L]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question