Performing redirects


Front-matter

You can perform a redirect from any page, entry, etc, by adding a redirect variable to the front-matter.

For example, our page named site/pages/bacon-of-the-week/index.md, you might have the following:

---
title: Bacon of the Week
redirect: /bacon/applewood
---

Now, when you visit /bacon-of-the-week, you will be taken to /bacon/applewood.

Route data

The same style of redirect can be added directly to your routes:

routes:
  /bacon-of-the-week:
    redirect: /bacon/applewood

Templates

Sometimes it makes sense to perform a redirect within a template. Perhaps you have some conditional logic for performing the redirect.

For that, you may use the aptly named Redirect Tag.

{{ if should_redirect_for_whatever_reason }}
  {{ redirect to="/bacon/applewood" }}
{{ /if }}

Vanity Routes

You may set Vanity Routes from within your routes file, under the vanity key.

vanity:
  /bacon-of-the-week: /bacon/applewood

.htaccess

This isn’t really part of Statamic at all, but it will yield the most zippy results since the server would know to perform the redirect before Statamic even gets loaded.

This is the preferred method for permanent redirects.

Last modified on June 13, 2017