Redirects

To create redirections from one page to other

Options See on deno.land

output html json netlify vercel function

The redirects output format

Default:
"html"
defaultStatus 301 302 307 308

The default status code to use

Default:
301

Description

This plugin allows to create redirections from one page to other. It can output Netlify and Vercel config files, JSON and HTML pages with http-equiv="refresh" meta tags.

Installation

Import this plugin in your _config.ts file to use it:

import lume from "lume/mod.ts";
import redirects from "lume/plugins/redirects.ts";

const site = lume();

site.use(redirects());

export default site;

Usage

Let's say you have the following page in your site:

---
url: /articles/hello/
---

At some point, you decide to change the url to simply /hello/. All urls to /articles/hello/ will be broken and the SEO ranking lost. To avoid that, you can create a redirection from the old url to the new one, so both links will work fine. You only have to create the oldUrl variable with the previous url:

---
url: /hello/
oldUrl: /articles/hello/
---

Use an array to specify more than one old URL:

---
url: /hello/
oldUrl:
  - /articles/hello/
  - /articles/older-hello/
---

The plugin will generate automatically the redirections from the old page(s) to the new one. There are 4 different output methods:

  • html: It's the default value. It creates an html page for each old url with a <meta http-equiv="refresh" content="0; url="..."> tag. This method doesn't require any server configuration.
  • json: To create the _redirects.json JSON file with all redirects, compatible with the redirects middleware, which works on Deno Deploy.
  • netlify: To create (or update) a _redirects file, compatible with Netlify.
  • vercel: To create (or update) the vercel.json file with all redirects.

Example:

site.use(redirects({
  output: "netlify",
}));