Web Island Agency

How to do redirects on Netlify

How to do redirects on Netlify
How to do redirects on Netlify

Redirection is a process of forwarding users from one URL to another. Netlify provides a simple and straightforward way to set redirects for your website. Netlify redirects are definable in a _redirects file added to your website folder.

There is nothing difficult about redirects definition. To set up a basic redirection write source URL and target URL in one row. Examples of basic redirects are listed below:

/home               /
/blog/index.html    /blog
/articles           /blog
/external           https://example.com

If you begin a line with # it will be recognized by the Netlify redirects engine as a comment. The redirect engine parses rules from top to bottom and triggers on the first matching rule.

The default HTTP status code is 301. If you need to take control of it, just put the status code as a third value in the rule row. For example:

# 301 Redirect
/blog         /articles         301

# 302 Redirect
/static       /temp             302

# Rewrite a path
/proxy        /index.html       200

# Custom 404
/dev-wanted   /vacancy-closed   404

If you assign 301, 302 or 303 status code to redirect rule, Netlify will redirect to the destination URL. Any other code will force Netlify to return the target document with the specified status code. Specifying 200 as a status code, Netlify will work just like a regular proxy with some security restrictions.

In the next article I'll cover setting up Netlify redirects for Jekyll website, common issues and their solutions.

Join the discussion!

The article is published under the tags

Read more articles related to the topic