A site that’s been around a while has addresses that people have bookmarked, that other sites link to, and that search engines rank. Moving the site means keeping every one of those addresses working, even when the new site is laid out differently. Set up those addresses before the domain moves, while the old site is still up.
List the old addresses
Most sites have a sitemap. Save its addresses, as paths, to a file:
curl -s https://www.example.com/sitemap.xml \
| grep -o '<loc>[^<]*' | sed -E 's#<loc>https?://[^/]+##' > old-addresses.txt
A sitemap can list other sitemaps, like /sitemap-pages.xml: fetch each of them the same way. Add any other address you
know is linked to but isn’t in a sitemap, like an old campaign’s page or a PDF.
Keep each one working
Each old address should be a page on the new site, or a redirect to where it moved:
- Same address: a page at the same path needs nothing.
/aboutispages/about.html, and/team/samispages/team/[slug].htmlwith a team member whose slug issam. - A slash at the end:
/about/redirects to/aboutautomatically. - A file, like a PDF that’s linked to: put it in
public/, at the same path.public/brochure.pdfis served at/brochure.pdf, exactly as it is. - Gone: an old address with no page to take its place can be left to the
404page. Redirect it only if another page does the same job: redirecting everything to the home page tells search engines the old pages are gone anyway. - Moved: list it in
redirects.yaml, at the site’s root:
/about-us: /about
/blog: /news
/blog/*: /news/* # everything under /blog, keeping the rest of the path
/shop: https://shop.example.com # somewhere else entirely
Each redirect is a 301, which means the page moved for good. Search engines carry the page’s ranking over to its new
address. A redirect only applies where there’s no page. The checker warns about a redirect to a path that has no page.
Check them
Serve the new site with tekt start, and ask it for every old address:
while read -r old; do
printf '%s %s\n' "$(curl -s -o /dev/null -w '%{http_code}' "http://localhost:4321$old")" "$old"
done < old-addresses.txt | grep -Ev '^(200|301) '
Every address the loop prints is neither a page nor a redirect. Add a page or a redirect for each one. For an address
you’ve decided to leave to the 404 page, take it out of old-addresses.txt instead. Run the loop again until it
prints nothing.
Switch the domain
- Publish the new site.
- In the new site’s Settings › General, add the domain, and add the TXT record first. The TXT record proves the domain is yours while the old site is still being served.
- Point
wwwat Hypertekt: add the CNAME record, in place of the old site’s CNAME, A or AAAA records forwww. Leave the domain’s other records, like the MX records for email, as they are. Visitors reach the new site once DNS sees the change and Hypertekt has made the domain’s certificate. That usually takes a few minutes.
Connect a domain has the details.
Afterward
- In Google Search Console, check that the site is still verified, and give it the new
/sitemap.xml. Over the next few weeks, watch the Pages report for addresses Google can’t find. - From now on, Hypertekt keeps addresses working automatically. When a page’s file is renamed or an item’s slug changes, the old address redirects to the new one. A deleted page’s address tells search engines the page is gone.