Ga naar inhoud

πŸ‡¬πŸ‡§ Netlify redirect info

Save a plain text file called _redirects to the publish directory of your site.

In a _redirects file, each redirect rule must be listed on a separate line, with the original path followed by the new path or URL. Any line beginning with # will be ignored as a comment.

Here is an example:

#Redirects from what the browser requests to what we serve
/home / 301
/blog/my-post.php /blog/my-post 301
/news /blog 301
/cuties https://www.petsofnetlify.com 301
The redirects engine will process the first matching rule it finds, reading from top to bottom. Rules in the _redirects file are always processed first, followed by rules in the Netlify configuration file.

The following example uses _redirects file syntax:

#This rule will trigger at /blog/my-old-title
/blog/my-old-title /blog/my-new-title 301
#This rule will never trigger because the previous rule triggers first
/blog/my-old-title /blog/an-even-better-title 301

HTTP status codes

HTTP status codes are sent in server responses to the client or browser. The code gives information about the type of response.

You can specify the HTTP status code for any redirect rule. If left unspecified, the default is 301.

Here are some examples of status codes you might use:

  • 301 (default): Permanent redirect. Tells the client that the address for this resource has permanently changed, and any indexes using the old address should start using the new one. The URL in the browser address bar will display the new address.

  • 302: Temporary redirect. Tells the client that the current address change is temporary. The URL in the browser address bar will display the new address.

  • 404: β€œNot found”. You can use this status code to present custom 404 pages when visitors access paths on your site that don’t exist. With this status code, the page content will change, but the URL in the browser address bar will not.

  • 200: β€œOK”. Redirects with this status code will change the server response without changing the URL in the browser address bar. This is used for rewrites and proxying.

Here are some example redirect rules with status codes:

Redirect with a 301

/home / 301

Redirect with a 302

/my-redirect / 302

Show a custom 404 for this path

/ecommerce /store-closed 404

Rewrite a path

/pass-through /index.html 200