Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 31, 2025

Sites hosted on GitHub Pages with custom domains have duplicate content at both username.github.io and customdomain.com, causing SEO issues. Adding canonical URLs tells search engines which URL is authoritative.

Changes

  • layouts/partials/header.html: Add canonical <link> tag using Hugo's .Permalink (which derives from baseURL). Supports existing relcanonical front matter for page-specific overrides.
  • layouts/_default/single.html: Remove duplicate canonical handling (now centralized in header.html).

Usage

Set your custom domain in hugo.yaml:

baseURL: https://customdomain.com/

All pages automatically get canonical URLs pointing to your custom domain. Individual pages can override via front matter:

---
relcanonical: /some/other/path
---

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • publish.twitter.com
    • Triggering command: /tmp/hugo hugo --themesDir ../.. (dns block)
    • Triggering command: /tmp/hugo hugo (dns block)
    • Triggering command: /tmp/hugo hugo --renderToMemory (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Feature Request: support custom domains</issue_title>
<issue_description>I have tried to set up a custom domain for a personal GitHub page. It works smoothly but I noticed some SEO problems because of the duplicate content at username.github.io and customdomain.com

The internet suggests the following solution:
add to the head

<meta http-equiv="refresh" content="0; URL=https://customdomain.com/">
<link rel="canonical" href="https://customdomain.com/">

I considered modifying just my fork of the theme, but I am now wondering if there are other places where
the custom domain should be added.

It is also unclear why there are two different parameters for the site URL: baseURL in hugo.yaml and openGraph.url.
Is there any case where they should differ from each other?

Since this may be a common situation, adding an option to the theme to support custom domains may be worth adding.
</issue_description>

Comments on the Issue (you are @copilot in this section)

@BernatBC Hi @maiani, sorry for the late response. I also have a custom domain, and I don't have any problems. I just added my custom domain into `hugo.yaml`, and followed the guide on github pages.

However, if you really wanted to add the html metadata, you can create a file into your site's layout/partials/header.html, paste the content of this file: https://github.com/hugo-toha/toha/blob/main/layouts/partials/header.html, and add your lines there.

Hope this solves the issue</comment_new>


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@netlify
Copy link

netlify bot commented Dec 31, 2025

Deploy Preview for toha-ci ready!

Name Link
🔨 Latest commit c213945
🔍 Latest deploy log https://app.netlify.com/projects/toha-ci/deploys/695531b30b09a70008a9c7f6
😎 Deploy Preview https://deploy-preview-1117--toha-ci.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copilot AI changed the title [WIP] Add support for custom domains in theme Add canonical URL support for custom domains Dec 31, 2025
Copilot AI requested a review from hossainemruz December 31, 2025 14:24
@hossainemruz
Copy link
Member

@copilot Do we need <meta http-equiv="refresh" content="0; URL=https://customdomain.com/">?

Copy link
Contributor Author

Copilot AI commented Dec 31, 2025

@copilot Do we need <meta http-equiv="refresh" content="0; URL=https://customdomain.com/">?

No, the <meta http-equiv="refresh"> tag is not needed. The <link rel="canonical"> tag is the correct solution for the SEO duplicate content issue - it tells search engines which URL is authoritative without redirecting users. A meta refresh would forcibly redirect visitors, which isn't necessary since GitHub Pages serves the same content on both domains. The canonical tag lets search engines know which URL to index while users can still access the site from either URL.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: support custom domains

2 participants