One of the things I highly value is stable URLs. When you link to my site, I want that URL to work as long as my site is up. I don't want to lose all those links lightly. But for ease of implementation, the URL structure matches the file structure on my site, and I occasionally want to change the file structure. So what should I do?
I make a 301 redirect from the old URL to the new URL.
There are links on forums, discord, stackoverflow, etc. that I can't expect anyone to change. But I can keep those links working on my end by adding a redirect. I have made 28 of these URL changes in 28 years, an average of once year, and each one has a redirect to keep the old URLs working.
In this case I wanted to move https://www.redblobgames.com/grids/line-drawing.html to https://www.redblobgames.com/grids/line-drawing/ . The original plan back in 2011 was to have a main page about grids and then a few pages that went along with that. The line drawing page was one one the accompanying pages. But I never did write a main page, so now the line drawing page is its own project. I want to move it into its own folder so that I can add more pages to the project, including a comparison to Bresenham's Line Algorithm. Here were the steps:
- Move the files
cd grids/
mkdir line-drawing
mv line-drawing.bxml line-drawing/index.bxml
mv line-drawing.html line-drawing/index.html
mv line-drawing.js line-drawing/line-drawing.js
mv line-drawing.org line-drawing/index.org
mv line-drawing.png line-drawing/
mv _line-drawing-helper.js line-drawing/
- Test the new page locally
- Create a permanent redirect
- Test the redirect
- Update links from the rest of my site
- https://www.redblobgames.com/
- https://www.redblobgames.com/grids/hexagons/
- https://www.redblobgames.com/grids/line-drawing/
- https://www.redblobgames.com/grids/parts/
- https://www.redblobgames.com/making-of/line-drawing/
- https://www.redblobgames.com/making-of/diagram-structure/
- https://www.redblobgames.com/making-of/little-things/
- https://simblob.blogspot.com/2014/12/line-drawing-on-grid-maps.html
- https://simblob.blogspot.com/2016/12/five-year-mission.html
- https://simblob.blogspot.com/2017/05/making-of-line-drawing-tutorial.html
- https://simblob.blogspot.com/2018/02/how-i-implement-my-interactive-diagrams.html
- https://simblob.blogspot.com/2019/03/brainstorming-with-factoring.html
- https://simblob.blogspot.com/2023/01/making-of-circle-drawing.html
I run a staging server locally so that I can test all of my pages before I upload them. I want to make sure I get all the supporting files, and I also want to make sure any relative links to ../
get changed to ../../
. I use the Network panel in the browser tools to make sure there are no 404s. It turns out I had missed some files, so I'm glad I tested this before uploading it.
I'm using Nginx for redblobgames.com, so I added this to nginx.conf
:
location = /grids/line-drawing.html { return 301 $scheme://www.redblobgames.com/grids/line-drawing/; }
I then have to tell nginx to load the updated configuration file:
sudo service nginx reload
It turns out I had gotten this wrong, initially putting location ~
. I rarely edit my nginx file so I keep forgetting the various rules for matchers.
This means the site was broken for a few minutes while I fixed the bug. If I were more disciplined I'd have a staging server for testing nginx configuration, but my staging server runs Caddy so I don't catch this type of bug. I rarely change my nginx.conf
though, so it's a low priority to add tests here.
Since I set up a redirect, I don't have to update the links, but I think it's good to do it anyway. My upload script checks local links and gave me a list of pages to update:
I went through each one and changed the links manually. I don't have an automated tool for this (other than occasionally using perl -i -pe
) because it's not a common thing I do.
However I still have links on my blog that aren't included here. Moving my blog from blogspot to my own site is another project. Until then, I have search for links in two places.
I went through each one and changed the links manually. I can't use perl -i -pe
here because blogspot requires me to edit through their editor instead of editing files.
I think everything works now.
Also see: Cool URIs don't change
Labels: infrastructure
Thanks for keeping it updated!
Post a Comment