Skip to content

Instantly share code, notes, and snippets.

@tatethurston
Last active July 24, 2023 19:53
Show Gist options
  • Save tatethurston/55cd535b12c973c47cd24dbd4e866bde to your computer and use it in GitHub Desktop.
Save tatethurston/55cd535b12c973c47cd24dbd4e866bde to your computer and use it in GitHub Desktop.
AWS Amplify Redirect Rules for SEO
Source address Target address Type Country code
https://tatethurston.com https://www.tatethurston.com 301 (Redirect - Permanent) -
/<a>/ /<a> 301 (Redirect - Permanent) -
/<a>/<b>/ /<a>/<b> 301 (Redirect - Permanent) -
/<a>/<b>/<c>/ /<a>/<b>/<c> 301 (Redirect - Permanent) -
/<\*> /404 404 (Rewrite) -
@tatethurston
Copy link
Author

tatethurston commented Jul 24, 2023

All of the above work to ensure a single canonical URL

  • The first entry redirects apex requests to the www subdomain
  • The <a>, <b>, <c> redirects strip trailing slashes from URLs, up to 3 levels deep. Ideally, this would be done with a regex, but Amplify does not seem to support capture groups and has yet to document regex usage in any meaningful capacity.
  • The last entry redirects all 404s to the 404 route.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment