Search code examples
http-redirectssl-certificategithub-pagescloudflareidn

A GitHub Page website when having a custom domain redirects too many time. How to identify the bug?


This repo has been successfully added a GitHub Page. On local or when no custom domain is added (i.e. be visited at https://username.github.io/repo-name/) it works fine, indicating that the code has no bug. However, when I add an internationalized domain name (kiếmtiền.quảcầu.ccxn--kimtin-xi8bta.xn--qucu-hr5aza.cc), it redirects too many times. The content that Facebook Debugger can read is:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>301 Moved Permanently</title>
</head>
<body>
<center><h1>301 Moved Permanently</h1></center>
<hr>
<center>nginx</center>
</body>
</html>

When I use the domain with a test repo it works fine, indicating that either GitHub has no problem with IDN and the setup Cloudflare is fine:

enter image description here

When I try turning off the proxy, on Firefox I get SSL_ERROR_BAD_CERT_DOMAIN, and on Edge I get NET::ERR_CERT_COMMON_NAME_INVALID.

I don't know how to investigate any further. Do you have any idea?


Solution

  • GitHub Pages redirects HTTP traffic to HTTPS. If your Cloudflare encryption mode is set to Flexible Cloudflare sends requests to your origin (GitHub Pages) over HTTP. This results in the redirect loop you're experiencing. To fix this issue:

    • Go into your Cloudflare account
    • Enter your zone and go to SSL/TLS > Overview.
    • Now select Full as the encryption mode.

    Screenshot of the option in the Cloudflare Dashboard:
    Screenshot of the option in the Cloudflare Dashboard

    Read more about Cloudflare's encryption modes: https://developers.cloudflare.com/ssl/troubleshooting/too-many-redirects/#flexible-encryption-mode