Need help with stopping redirection of netlify custom domain to gh-pages site

Hi team,

I have a custom domain abhijeetsaxena.in configured for my netlify account.I remember I had also properly setup the redirect behavior such that it used to properly redirect gh-pages site to my netlify homepage site without any issues. For few repositories, it seems to work fine but for a recent project I created, when I got to my custom domain it just redirects to gh-pages url

For example,

https://github.com/abhijeet-saxena/wysiwyg this repository has a gh-pages site but when I go to WYSIWYG Editor it renders properly without changing URL

However, I created a project recently at GitHub - abhijeet-saxena/wordle: My own take on the viral word game WORDLE and for some reason going to abhijeetsaxena.in/wordle/ automatically redirect me to abhijeet-saxena.github.io/wordle/

My homepage’s netlify.toml file

[[redirects]]
from = '/*'
to = 'https://abhijeet-saxena.github.io/:splat'
status = 200

[[headers]]
for = "/*"
[headers.values]
X-Frame-Options = "SAMEORIGIN"
X-XSS-Protection = "0"
X-Content-Type-Options = "nosniff"
Content-Security-Policy = "default-src 'self'; style-src 'self'; form-action 'self'; script-src 'self'; connect-src 'self'; img-src 'self'; base-uri 'self';"

I tried to go through the docs and see if I can find something but as its working fine for few sites and not working for one I’m not exactly sure if its a config thing or something else. Kindly help.

Thanks,
Abhijeet

hi there, how recently did you create these redirects?

also, could you tell us your netlify site name or API ID (safe to share) please?

These redirects have been in place since September 2021.

Site Name: abhijeet-saxena
API ID: 105cf054-6128-4e73-b552-2ec02ff03441

This is the main site that corresponds to my gh-pages homepage at GitHub - abhijeet-saxena/abhijeet-saxena: My Personal Site
So technically any project under my GitHub and deployed on gh-pages should also be available as a subpath after my custom domain.

I think I know what the issue is, I noticed that a trailing slash leads to proper behavior.
For example, https://abhijeetsaxena.in/wordle/ behaves correctly, but when I use https://abhijeetsaxena.in/wordle it redirects to https://abhijeet-saxena.github.io/wordle/ which is not what I want.

I’m suspecting it has something to do with how :splat is configured. I also looked into Redirect options | Netlify Docs

Can you help me identify the problem ?

I think Bug in non-trailing slash rewrite is something related to this

Hi @abhijeet-saxena

I am curious why you have a wildcard proxy rewrite in the netlify.toml.

[[redirects]]
  from = '/*'
  to = 'https://abhijeet-saxena.github.io/:splat'
  status = 200

This rule is rewriting/proxying everything that doesn’t exist to GitHub e.g.

Better to have a specific rule for /wordle e.g.

[[redirects]]
  from = '/wordle/*'
  to = 'https://abhijeet-saxena.github.io/wordle/:splat'
  status = 200

@coelmay Actually, I have multiple projects, so I was trying to handle this all at once. Will I need to setup redirects for each of my projects in github ?

Also, I tried to add the suggested redirect to my netlify.toml file but doesn’t seem to make any difference

[[redirects]]
  from = '/wordle/*'
  to = 'https://abhijeet-saxena.github.io/wordle/:splat'
  status = 200
[[redirects]]
  from = '/*'
  to = 'https://abhijeet-saxena.github.io/:splat'
  status = 200
[[headers]]
  for = "/*"
  [headers.values]
    X-Frame-Options = "SAMEORIGIN"
    X-XSS-Protection = "0"
    X-Content-Type-Options = "nosniff"
    Content-Security-Policy = "default-src 'self'; style-src 'self'; form-action 'self'; script-src 'self'; connect-src 'self'; img-src 'self'; base-uri 'self';"

I added these redirects to a test site. Browsing to /wordle/ loads fine. But unlike your site /wordle does not redirect, rather it fails to load page resources as it is looking at the site root. This is fixable with <base>.

This behaviour is the same using https://abhijeetsaxena.in/wordle/ vs https://abhijeetsaxena.in/wordle too when I try a different browser (redirect is likely cached now.) Can you try a different browser to see what result you get.

@coelmay Yup, you’re right. In a different browser, it is working. I did have to set the correct <base> to import the assets from the right path.

Can you suggest a way in which I can handle this for multiple projects without cluttering up my netlify.toml file with each redirect rule? Because everytime I create a new project on gh-pages I’ll also have to handle that in the config

My suggestion is to create specific rules for each project.

If you didn’t have project paths based at the root of the domain and had them under projects you could add

[[redirects]]
  from = '/projects/*'
  to = 'https://abhijeet-saxena.github.io/:splat'
  status = 200

The GitHub 404 page would still show for any missing page under /projects though as is does currently for any path under /wordle that doesn’t exist.