What Is a Canonical URL?
Every page on the internet has an address. But sometimes the same page can be reached through different addresses. With a trailing slash or without. With "www" or without. Through HTTP or HTTPS.
A canonical URL is a page's way of saying "this is my real address." It is a small tag in the page's head section that tells search engines which version of the URL is the official one.
Why Search Engines Care
When a search engine finds the same content at two different addresses, it has a problem. Should it show both in search results? Should it split the ranking between them? Which one is the "real" page?
The canonical tag answers that question directly. It points to the one true URL. The search engine can then focus its attention there and ignore the duplicates.
How the Build Script Handles It
In our source files, we do not write out the full canonical URL by hand. That would mean updating it every time we moved a page or changed the site's domain.
Instead, the build script calculates it. It looks at where the file lives in the folder structure and converts that path into a URL. A file at src/pages/campus/build-a-game/index.html becomes https://lightschool.com/campus/build-a-game/. The script knows the site's base URL from the config file and builds the rest from the file path.
The Sitemap Connection
The canonical URL is not just for the page itself. It also appears in the sitemap, which is a file that lists every page on the site for search engines to find. The sitemap and the canonical tags need to agree. If they show different URLs for the same page, the search engine gets confused.
Because both the sitemap and the canonical tags are generated by the same build script using the same logic, they always match. One source of truth, two outputs.
A Small Tag, a Big Difference
The canonical URL is a single line of HTML that most visitors will never see. But for search engines, it is an important signal. It keeps your site organized in their view and prevents your own pages from competing against each other in search results.
Automating it means we never forget to include it and never get it wrong. The build script does the work so we do not have to think about it.