Redirects of gh-hosted pages to custom domain

hey,

redirects have been discussed numerous times but somehow I can’t get it to work for my case.

I have two gh-hosted pages:

I would like to have the wiki and all of its content appear at www.asellus.org/wiki

This is what netlify.toml in the main repo looks like:

[[redirects]]
  from = "/wiki/*"
  to = "https://wiki.asellus.org/:splat"
  status = 200
  force = true

what am I doing wrong?

Hi @mluerig

It appears the location you are trying to redirect to wiki.asellus.org is not reachable

Other than this issue (likely the root cause), the redirect looks fine.

Have you added wiki.asellus.org as a custom domain to asellus-wiki.netlify.app?

for me https://www.wiki.asellus.org/ is reachable.

Have you added wiki.asellus.org as a custom domain to asellus-wiki.netlify.app ?

yes - or do you mean without www?

Without the www isn’t reachable, with the www is. The redirect has no www therefore the redirect will not work as the address redirecting (or in this case proxying) too is not reachable.

I would argue that a www on a subdomain (wiki in this case) is not a this usually done (though it is personal preference I guess) as the www is a subdomain of a subdomain.

I added wiki.asellus.org as a domain alias and now it’s working as expected.

one other thing: wiki.asellus.org is reachable and wont change the url - how can I accomplish that people are redirected to asellus.org/wiki?

You can add a domain-level redirect e.g.

[[redirects]]
  from = "https://wiki.asellus.org/"
  to = "https://asellus.org/wiki/"
  status = 301
  force = true

I suspect (I have not tried) that adding a :splat (as below) may in turn negate the call from the proxy causing an infinite loop

[[redirects]]
  from = "https://wiki.asellus.org/*"
  to = "https://asellus.org/wiki/:splat"
  status = 301
  force = true

In this case I believe the proxy would get redirected back on itself and fail.

[Support Guide] Making redirects work for you - troubleshooting and debugging is a great resource for everything redirects related.

that didn’t appear to work - the url remain unchanged.

this is the netlify config file - homepage/netlify.toml at master · The-Asellus-Consortium/homepage · GitHub - is this how you meant it?

Yes, that’s correct, but it needs to go into a netlify.toml in the repository of the wiki, not of the main site.

this does not work if I only add the second part (with or without splat) to the wiki repo

interestingly, now also the redirect from the main repo fails

As I mentioned previously, because you are proxying to the subdomain wiki.asellus.org, from asellus.org/wiki the wildcard/splat redirect would likely cause an infinite loop and fail (which it is.)

Try removing the wildcard/splat from the redirect in the wiki repository and the main site proxy should work again.

but that’s also what I said: I tried with and without the splat - and it didn’t work in either case.

I have now removed splat and wildcard in the wiki, and it still does not work

Of course, a wildcard/splat will match anything, including /, so it will still cause a infinite redirect loop :thinking:

So when https://asellus.org/wiki/ is requested it is actually calling https://wiki.asellus.org/, but this path is redirected to https://asellus.org/wiki/ thus the loop begins :thinking:

ok … so, not possible? sorry for being hard headed here…

In short, no, because it creates an infinite redirect.

1 Like

so leaving the domain level redirect aside for the moment, I encountered a new problem with the redirect when switching from jekyll to a legacy gitbook / honkit solution: the page builds correctly and is reachable under wiki.asellus.org, but the redirect fails now: the content is there, but the css is broken, and the intra-page links don’t work (the “wiki” is missing in the url).

In jekyll, I solved this with the baseurl option in the config file, but I am not sure there is a similar option for honkit. Do you have any suggestions how this could be solved from the netlify end?

I must say I haven’t used honkit.

Searching the git repository for the project, I do see basePath which is possibly a way to prefix all URLs with /wiki/ so they work under asellus.org/wiki/.

the honkit maintainer pointed out that asellus.org/wiki/ works, but asellus.org/wiki doesn’t.

I guess this means I am stuck again, because the domain level rewrite from asellus.org/wiki to asellus.org/wiki/ would result in the infinite loop we encountered before. is there no way to exclude a specific url form the wildcard? this would solve this issue and the one above (from wiki.asellus.org to asellus.org/wiki)

ok I solved the slash issue by activating asset optimization: Redirect options | Netlify Docs

still, exceptions to wildcard rules would be tremendously helpful to tackle the above problem

I celebrated too early: asset optimization removes the “wiki” bit from the gitbook’s internal urls, so this is not a solution

The simplest solution is to use absolute URLs for all your assets. Or store your assets in a different folder and you can redirect all those assets in one go, but this would probably be difficult to achieve.

It would have been possible to exclude a URL from the wildcard but that’s not possible in the proxy setup that you currently have.