Advanced Gatsby redirects now supported

The gatsby-plugin-netlify package now supports advanced Gatsby redirects.

These redirects can be added to your project by adding a gatsby-node.js file in the same directory as gatsby-config.js, then adding a exports.createPages function. See the examples below for details.

We’ve added support for five new types of redirects.

Examples

Wildcard path redirects

// Full example
exports.createPages = async ({ actions }) => {
	const { createRedirect } = actions;

	createRedirect({
    fromPath: `/blog/technology/*`,
    toPath: `/technology`,
  });
}

Splat redirects

createRedirect({
    fromPath: `/blog/recipes/*`,
    toPath: `/recipes/*`,
  });

Country-based redirects (use ISO 3166-1 alpha-2 codes for countries)

createRedirect({
    fromPath: `/blog`,
    toPath: `/canada/blog`,
    conditions: {
      country: `ca`,
    },
  });

Language-based redirects (use ISO 639-1 codes for languages)

createRedirect({
    fromPath: `/blog`,
    toPath: `/french/blog`,
    conditions: {
      language: [`fr`],
    },
  });

Query parameter redirects

createRedirect({
    fromPath: `/dogs?id=7`,
    toPath: `/greyhound`,
  });

// More advanced

createRedirect({
    fromPath: `/cats?id=:id`,
    toPath: `/cats/:id`,
  });

This topic was automatically closed after 14 days. New replies are no longer allowed.