+1 vote
Trying to set up a redirect to the home page if the wrong request in the address bar.
The code is as follows.

location / {
try_files $uri $uri/ /;
In principle it works as it should, but it is annoying that the address bar is left with a string of incorrect requests. For example, when typing http:/some.orgthere_is_no_resource , the code redirects to the right place, but the address line stays as requested. How can I tell nginx to remove erroneous $uri from the address bar?

1 Answer

0 votes
Best answer
Mb so:
# объявляем страницу с ошибкой
error_page 404 = @notfound;

# правило перенаправления для страницы 404
location @notfound {
return 301 /;