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.
Assume that you want to migrate
newsite.vercel.app. You have a domain name
Add a Record
Go to your domain registrar (e.g. GoDaddy) and add a record
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
After a while, the site refreshed:
Your site is live at https://newsite.com/
curl to visit
and you will find that the site is 301 redirect to the custom domain
$ 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
Update the Record
Go to your domain registrar and update the record to the final
(vercel/azure websites/self hosting).
Now your site is hosted on both
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.