DEV Community

Cover image for How To Redirecting All Traffic To Netlify
Irshad Ali
Irshad Ali

Posted on

How To Redirecting All Traffic To Netlify

Redirecting In Netlify

When we deploy a site in Netlify everything works pretty fin but when it comes to routing there are some errors like when we navigate to Blog page in a site it takes us to that's fin. But! When we refresh that same page then we see this screen.


To solve this problem

Thankfully,Netlify provides us a way to do this via a _redirects file. You need to make sure that this file sits at the root of your build directory.

So what to do?

Just create a new file with the name of _redirects and put this file in the root folder of your site. Then after add below code in that file. That's it

/* /index.html 200
Enter fullscreen mode Exit fullscreen mode

Above line states that we want all paths redirected to /index.html with response of 200.

Even you can redirects and rewrites

Add one or more redirects tables to your Netlify configuration file. This method allows for more structured configuration and additional capabilities, as described in the Netlify configuration file syntax section below.

home                     /
/blog/my-post.php        /blog/my-post
/news                    /blog
Enter fullscreen mode Exit fullscreen mode

You can customize and alter the redirect behavior by adding options to the end of each line. Visit the redirect options and rewrites and proxies docs for more details.


from: The path you want to redirect.
to: The URL or path you want to redirect to.
status: The HTTP status code you want to use in that redirect; 301 by default.

Top comments (0)