Answer the question
In order to leave comments, you need to log in
How can I configure nginx to redirect to the main page in case of an error in the request, displaying the correct address in the address bar?
Hello.
I'm trying to set up a redirect to the main page if the request is incorrect in the address bar.
The code is next.
location / {
try_files $uri $uri/ /;
}
In principle, it works as it should, but it's annoying that the wrong query string remains in the address bar. For example, when typing http://some.org/there is no such_resource , the code redirects to the right place, but remains in the address bar as requested. How can I tell nginx to remove the wrong $uri from the address bar?
Answer the question
In order to leave comments, you need to log in
Mb like this:
# объявляем страницу с ошибкой
error_page 404 = @notfound;
# правило перенаправления для страницы 404
location @notfound {
return 301 /;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question