How to redirect Nginx 400 error to website desired page?

I have a website for a client, but when I go to and insert special characters, let’s say$%#&, Nginx give me a 400 Bad Request error.

What I want here is, instead of that error, redirect the user automatically to the home page.

How can I do that?

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

@alainalemany does it work for you ?

nano /etc/nginx/sites-available/default


error_page code_number file_source;

e.g error_page 400 /;

service nginx restart

Thank you so much.

What I’m hosting is a web app, and its index y located in /web/app.php. So I put in Nginx:

error_page 400 /web/app.php;

It works perfectly, but now when the redirection happens, I can see the url How can I do to make it look just