Netlify Redirects

First, you need to create a _redirects file in the publish directory of your site. In this file, we can define our redirects with the following syntax:

/api/* /.netlify/functions/:splat 200

In the code sample above, the asterisk (*) is used to indicate anything that follows /api/ will be matched to anything that follows /.netlify/functions/. For example, if you are selling products and want to have an API endpoint available such as /api/products, it will be matched to your functions products.js available at /.netlify/functions/products. Additionally, you can add other options like a HTTP status code, query parameters, redirect by country or language, and more! For example, if you wanted to redirect to /produits instead of /products for people in France, you would specify it this way:

/api/produits /.netlify/functions/products 302 Country=fr

Another way to set up redirects in your app is via the netlify.toml file. If we take the same example as the one above, the syntax in the netlify.toml file would be:

redirects from = "/api/*" to = "/.netlify/functions/:splat" status = 200

As with the _redirects file, you can use additional options if you need to pass headers, conditions, query parameters, and more, for more complex applications.

# Netlify Redirects - Setting up redirects on... - netlify.com - Redirects and rewrites |... - netlify.com - Redirect options | Netlify... - netlify.com - Netlify CLI - netlify.com - Exploring Netlify Redirects:... - youtube.com