Redirect with splat and 200 status fails

Hi,

My example below aims to redirect https://95199651-9e81-4cae-a3a7-66398a9a5f62.netlify.app to https://eds-book.netlify.app/95199651-9e81-4cae-a3a7-66398a9a5f62/. For the target (single website), I’ve declared the following rule into netlify.toml.

[[redirects]]
from = “/95199651-9e81-4cae-a3a7-66398a9a5f62/*”
to = “https://95199651-9e81-4cae-a3a7-66398a9a5f62.netlify.app/:splat
status = 200
force = false

When I access the redirected webpage, it returns the following Application error message:

# Application Error

@https://eds-book.netlify.app/build/_shared/chunk-OCTKKCIL.js:26:2272 map@[native code] useMemo@https://eds-book.netlify.app/build/_shared/chunk-UAI5KRM7.js:6:23211 mi@https://eds-book.netlify.app/build/_shared/chunk-OCTKKCIL.js:32:3945 Po@https://eds-book.netlify.app/build/_shared/chunk-UAI5KRM7.js:6:16958 pc@https://eds-book.netlify.app/build/_shared/chunk-UAI5KRM7.js:8:43668 cc@https://eds-book.netlify.app/build/_shared/chunk-UAI5KRM7.js:8:39467 Rd@https://eds-book.netlify.app/build/_shared/chunk-UAI5KRM7.js:8:39398 ul@https://eds-book.netlify.app/build/_shared/chunk-UAI5KRM7.js:8:39258 Zu@https://eds-book.netlify.app/build/_shared/chunk-UAI5KRM7.js:8:35680 ic@https://eds-book.netlify.app/build/_shared/chunk-UAI5KRM7.js:8:34636 Il@https://eds-book.netlify.app/build/_shared/chunk-UAI5KRM7.js:1:8284 Ll@https://eds-book.netlify.app/build/_shared/chunk-UAI5KRM7.js:1:8675

I wondered if anyone is familiar with the error or solution to redirect the webpage.

The rule you have added does not match the description. I think what you want is to add a redirect for the 95199651-9e81-4cae-a3a7-66398a9a5f62 site with the contents:

[[redirects]]
from = "/*"
to = "https://eds-book.netlify.app/95199651-9e81-4cae-a3a7-66398a9a5f62/:splat"
status = 200
force = false

@hrishikesh thank you! I’ve added a redirect (see here) for the 95199651-9e81-4cae-a3a7-66398a9a5f62 site, however it doesn’t work. Please note that I removed redirect for the eds-book.netlify site.

If it helps, I’m following the instructions of this blog post on building multiple GitHub repositories into a single website, How to Deploy Multiple Repositories to Subfolders Under One Website with Netlify - Bomberbot.

You have your own index.html for the 95199651-9e81-4cae-a3a7-66398a9a5f62 site. If you wish to ignore it, you need to change the force to true. This is mentioned in the docs.

I have change the force to true. The site now returns 404.

That’s because your original site (the one you’re rewriting to) is throwing a 404: Page not found.

I’m confused at this point. The website is throwing a 404, after the suggested changes in the toml file in 95199651-9e81-4cae-a3a7-66398a9a5f62 site.

[[redirects]]
  from = "/*"
  to = "https://eds-book.netlify.app/95199651-9e81-4cae-a3a7-66398a9a5f62/:splat"
  status = 200
  force = true

If I change force to false, the site is back (as per now) without 404.

@hrishikesh I’ve been successful in redirecting the expected file from the 95199651-9e81-4cae-a3a7-66398a9a5f62 site into Live-stock detection (DeepForest) - Livestock detection using DeepForest (Jupyter Notebook) published in the Environmental Data Science book, however it seems the logo at the top left isn’t retrieved because the redirect rules. Sharing the rule below:

[[redirects]]
  from = "/gallery/95199651-9e81-4cae-a3a7-66398a9a5f62/*"
  to = "https://95199651-9e81-4cae-a3a7-66398a9a5f62.netlify.app/:splat"
  status = 200
  force = false

I wondered which is the best practice to keep the logo.

Your advice would be welcome.

@acocac The URL of your logo is:

/build/config-item-325a78b3-ec17649c4500e98ac578cbf3b8ed3524.png

image

As you have already linked, there is no file at:
https://eds-book.netlify.app/build/config-item-325a78b3-ec17649c4500e98ac578cbf3b8ed3524.png

The rewrite that you have specified is:

[[redirects]]
  from = "/gallery/95199651-9e81-4cae-a3a7-66398a9a5f62/*"
  to = "https://95199651-9e81-4cae-a3a7-66398a9a5f62.netlify.app/:splat"
  status = 200
  force = false

That applies only to URL’s starting with /gallery/95199651-9e81-4cae-a3a7-66398a9a5f62/

It doesn’t apply to URL’s starting with /build/

If you want it to, then you need to either modify it, or add another rewrite rule accordingly.

For example:

[[redirects]]
  from = "/build/*"
  to = "https://95199651-9e81-4cae-a3a7-66398a9a5f62.netlify.app/build/:splat"
  status = 200
  force = false

Note: This may or may not break other things, I’ve not looked closely at all your URL’s

Hi @nathanmartin,

I’ve tested the solution of adding an additional rewrite rule. It works fine for a single external site, however it doesn’t show the logo when calling multiple sites, only one of them. See how I declare for other sites below:

[[redirects]]
  from = "/build/*"
  to = "https://95199651-9e81-4cae-a3a7-66398a9a5f62.netlify.app/build/:splat"
  status = 200
  force = false

[[redirects]]
  from = "/gallery/95199651-9e81-4cae-a3a7-66398a9a5f62/*"
  to = "https://95199651-9e81-4cae-a3a7-66398a9a5f62.netlify.app/:splat"
  status = 200
  force = false

[[redirects]]
  from = "/build/*"
  to = "https://39d9c177-11da-41b2-9b64-63f4c1c834b3.netlify.app/build/:splat"
  status = 200
  force = false

[[redirects]]
  from = "/gallery/39d9c177-11da-41b2-9b64-63f4c1c834b3/*"
  to = "https://39d9c177-11da-41b2-9b64-63f4c1c834b3.netlify.app/:splat"
  status = 200
  force = false

[[redirects]]
  from = "/build/*"
  to = "https://ea34568e-d86e-4720-be2f-3f826f66a26c.netlify.app/build/:splat"
  status = 200
  force = false

[[redirects]]
  from = "/gallery/ea34568e-d86e-4720-be2f-3f826f66a26c/*"
  to = "https://ea34568e-d86e-4720-be2f-3f826f66a26c.netlify.app/:splat"
  status = 200
  force = false

Logo is shown only for 95199651-9e81-4cae-a3a7-66398a9a5f62 (see here), but not for the others (39d9c177-11da-41b2-9b64-63f4c1c834b3 and ea34568e-d86e-4720-be2f-3f826f66a26c).

How do you suggest to keep artefacts such as a logo from the build folder across multiple external sites?

@acocac I wasn’t aware you were working with “multiple sites”.

I don’t quite understand why you’re doing it the way you are, but I can see immediately why the rules you’ve specified don’t work.

You can’t have multiple identical from values, pointing to different to destinations.

See the Rule Processing Order documentation.

The redirects engine will process the first matching rule it finds, reading from top to bottom. Rules in the _redirects file are always processed first, followed by rules in the Netlify configuration file.

The reality of your situation, based on the links you’ve provided, appears to be:

Site #1
-------
url:
  https://eds-book.netlify.app/gallery/95199651-9e81-4cae-a3a7-66398a9a5f62/notebook
logo's root relative url in source:
  /build/config-item-325a78b3-ee0f6b0682327861e209afb58f83a539.png
logo's absolute url:
  https://95199651-9e81-4cae-a3a7-66398a9a5f62.netlify.app/build/config-item-325a78b3-ee0f6b0682327861e209afb58f83a539.png

Site #2
-------
url:
  https://eds-book.netlify.app/gallery/39d9c177-11da-41b2-9b64-63f4c1c834b3/notebook
logo's root relative url in source:
  /build/config-item-325a78b3-ab705b3f81128c3cba0b7454f6837a6b.png
logo's absolute url:
  https://39d9c177-11da-41b2-9b64-63f4c1c834b3.netlify.app/build/config-item-325a78b3-ab705b3f81128c3cba0b7454f6837a6b.png

Site #3
-------
url:
  https://eds-book.netlify.app/gallery/ea34568e-d86e-4720-be2f-3f826f66a26c/notebook
logo's root relative url in source:
  /build/config-item-325a78b3-26bdab779e0b43753b3dfe9c2193199e.png
logo's absolute url:
  https://ea34568e-d86e-4720-be2f-3f826f66a26c.netlify.app/build/config-item-325a78b3-26bdab779e0b43753b3dfe9c2193199e.png

Factoring in the ‘Rule Processing Order’, means that on all of your sites, it is only using the first /build/* rule that it encounters (the one for Site #1).

All the other rules targeting the same from are being ignored.

The logo’s don’t load on Site #2 & Site #3, because it’s always using the first rule, and they don’t exist on Site #1

E.g.
https://95199651-9e81-4cae-a3a7-66398a9a5f62.netlify.app/build/config-item-325a78b3-ab705b3f81128c3cba0b7454f6837a6b.png
https://95199651-9e81-4cae-a3a7-66398a9a5f62.netlify.app/build/config-item-325a78b3-26bdab779e0b43753b3dfe9c2193199e.png

Most of the ways I can think around it, would require adjusting what your sites produce.

For example, hosting all the logos without sha’s in a central location.
Or ensuring they aren’t all in the same “folder” so they can be targeted and rewritten on a per-site basis.

As it stands, I believe the only way you could target them for individual rewrites would be by their filename, and if that filename is generative you’re going to encounter future issues.

@nathanmartin - thanks for all suggestions!

What do you mean by hosting all the logos without sha’s in a central location? Do you have example(s) of this deployment/setup in Netlify?

My temporary workaround so far has been removing the logo image and replace it by a text. All “multiple sites” display it without adding any specific redirect rule.

I just mean, “put them somewhere else” where they can remain static and be linked to easily.
E.g. If you had a single central shared site, of just your assets, named simply.
By not having sha’s I mean, just have them named like logo.png etc, so you know they won’t change.

No I do not.
It’s not a Netlify problem as far as I’m concerned.
It’s an engineering one in terms of how you’re trying to link a bunch of sites together.

Sounds like a perfectly fine workaround to me.