• Home
  • Blog
    • Programming
    • Art
    • Recipes
    • Home Automation
    • Life
    • Friday Faves
    • Books
    • Writing
    • Games
    • Web Accessibility
    • Advent of Code
  • Projects
  • GLSL Shader Art
  • Glitch Art

  • Github
  • Bluesky
  • Mastodon
  • Duolingo
  • LinkedIn
  • RSS
  • Bridgy Fed

mary.codes

Web development, art, and tinkering with fun projects. JavaScript, Python, WebGL, GLSL, Rust, Lua, and whatever else I find interesting at the moment.

Domain redirects with Netlify and Gatsby

Mary KnizeBlog iconMay 19th, 2021
1 min read

Programming

Using Netlify's DNS to forward to a new domain name for my Gatsby blog.

I've recently migrated from GitHub Pages to Netlify. With GitHub Pages, I was having to do a separate build process and commit to create my site, whereas with Netlify, all I have to do is commit the changes to my Gatsby site to GitHub. Netlify checks the repo for changes and automatically builds everything.

One thing I wanted to do, now that I'm on Netlify, is forward my old domain name, maryknize.com, to a new domain name, mary.codes. I think it's so cool that I was actually able to get mary.codes as a domain name.

First, I had to add mary.codes as a new domain on my Netlify dashboard by clicking the "Add or register domain" button on the Domains tab. Netlify provides name servers to add to the domain registrar so I can use Netlify's DNS for my redirects, so I logged into my domain registrar's dashboard to change the name servers to Netlify's. Then, I waited for the changes to populate. It can take up to 24 hours, but it took less than 30 minutes in this instance.

Netlify Domains

Next, I navigated to my site dashboard and accessed the domain settings for this specific site.

Netlify site dashboard

Then, in the custom domains area, I clicked the "Add domain alias" button to add "mary.codes" and "www.mary.codes" as domain aliases. After those appeared, I clicked the "Options" button next to mary.codes and set it as the primary domain.

Netlify custom domains

At this point, if you navigated to mary.codes or maryknize.com, you would be able to access the site. However, the URL doesn't redirect yet. For that, I need to add a netlify.toml file to my static folder, to be bundled and served from the public folder on build. This is what my netlify.toml looks like:

[[redirects]]
from = "https://maryknize.com/*"
to = "https://mary.codes/:splat"
status = 301
force = true

[[redirects]]
from = "https://www.maryknize.com/*"
to = "https://mary.codes/:splat"
status = 301
force = true

[[redirects]]
from = "https://maryknize.netlify.app/*"
to = "https://mary.codes/:splat"
status = 301
force = true

Since Netlify automatically redirects http to https, all I need to do is specify the https redirects. Now, anything from maryknize.com, www.maryknize.com, or maryknize.netlify.app will redirect correctly to mary.codes.


Other Programming posts

How I'm organizing my work in 2024

Finding the Design Engineer within the Full-Stack Developer

Displaying the current Git branch in my Linux terminal prompt

Generating a 3D map with OpenStreetMap and A-Frame

Translating OpenStreetMap data to HTML5 Canvas with Rust and WebAssembly

Latest posts

I started painting again

100 days of Japanese on Duolingo

How I'm organizing my work in 2024

Watch the documentary 'Good Night Oppy' if you're feeling science-y

Sculpted robo-goldfish, a rainbow office building, and a look inside click farms