# Redirects

When switching to Nacelle from another platform, sometimes it's helpful to set up redirects for routes that no longer exist. A common example is when switching from a Shopify store configured with duplicate routes to a Product Detail Page.

For instance, if an item was available at both Route A and Route B:

Route Name Route
Route A https://example.com/products/my-awesome-product
Route B https://example.com/collections/awesome/products/my-awesome-product

If both routes were indexed by search engines but Route B no longer exists, we could preserve SEO by setting up redirect rules such that all traffic to Route B is redirected to Route A.

Configuring redirect rules with Vercel or Netlify is straightforward. The examples below redirect Route B to Route A. If your routing needs are different than the example, be sure to check out the links to Vercel & Netlify documentation, below.

# With Vercel

If deploying with Vercel, you should already have a vercel.json configuration file in your project root, to set environment variables.

Following Vercel's Routes documentation, we will use regex and Capture Groups to configure the redirect routes:

// vercel.json
"routes": [
  {
    "src": "/collections/([^/]+)/products/([^/]+)",
    "status": 301,
    "headers": { "Location": "/products/$2" }
  }
]

# With Netlify

If deploying with Netlify, create a netlify.toml configuration file in your project root, either through a text editor or with the Unix shell command:

touch netlify.toml

Following Netlify's Redirect documentation, we will use Splats and Placeholders to configure the redirect routes in netlify.toml:

# netlify.toml
[build]
  [[redirects]]
    from = "/collections/:collection/products/*"
    to = "/products/:splat"
    status = 301
    force = true