Migrate GitHub Pages by 301 Redirects

GitHub Pages cannot perform HTTP 301 redirects as you cannot modify the server config. However, 301 redirects is really crucial for SEO. In order to keep the site ranking, you need to 301 redirects the old GitHub Pages to your new site, and manually notify Google Search Console:

Do you lose credit for links when you redirect to new URLs?
No, 301 or 302 redirects do not cause a loss in PageRank

So how to migrate GitHub Pages to a new site without losing site ranking?


  • A domain name

The idea is that we leverage GitHub Pages custom domain to perform 301 redirects.

Migration Steps

Assume that you want to migrate oldsite.github.io to newsite.vercel.app. You have a domain name newsite.com.

Add a Record

Go to your domain registrar (e.g. GoDaddy) and add a record newsite.com -> oldsite.github.io.

Add a custom domain in GitHub Pages (301 redirects)

Go to: GitHub Pages Repository Settings -> Pages -> Custom domain

Add your domain name (e.g. newsite.com) to the custom domain and press Save.

After a while, the site refreshed:

Your site is live at https://newsite.com/

Use curl to visit https://oldsite.github.io and you will find that the site is 301 redirect to the custom domain name:

$ curl -I https://oldsite.github.io
HTTP/1.1 301 Moved Permanently
Connection: keep-alive
Content-Length: 162
Server: GitHub.com
Content-Type: text/html
permissions-policy: interest-cohort=()
Location: http://newsite.com/

Now your site is available at both https://newsite.com/ and https://oldsite.github.io.

Update the Record

Go to your domain registrar and update the record to the final target: newsite.com -> newsite.vercel.app (vercel/azure websites/self hosting).

Now your site is hosted on both https://newsite.com/ (newsite.vercel.app) and https://oldsite.github.io. All traffic to the old site will be 301 redirected to the new site.

After several days (half a year or longer), your site will be completely migrated to the new site without pagerank loss. Then you can safely deleted the old GitHub Pages.