Eleventy to redirect to an Obsidian Publish

Howdy,

I’m having a similar issue with my website, and I’ve tried implementing some version of the guidance here to no avail. I’m using Eleventy to redirect to an Obsidian Publish.

My code is here. My parent website is here, and the redirect happens here.

I have a netlify.toml file with a redirect in it per the Obsidian documentation. I’m pretty sure this additional redirect is not being counted as netlify is just showing 1 and not 2 of them. I’ve tried having _redirects in my root and in a file named public, but neither has worked. I’ve also tried to take the workaround @jaylowe1 used and apply it to my package.json. But I’m fairly confident that I’m likely not experiencing the same issue, and if I am, I’ve gone about resolving it incorrectly.

Redirects (and backend in general) are new and incredibly confusing to me. Because of my lack of understanding, I think there is probably something wrong with how I have my netlify.toml and _redirects file set up that prevents them from working together.

My guess is that the issue is in my netlify.toml file, but I’m totally lost here.

Any help would be greatly appreciated and your name will be shouted in praise from the mountaintops. I may even name my firstborn after you (I’m really really lost if it isn’t clear lol).

Hi @realbearsmith

As stated in Redirects and rewrites → Rule processing order

Rules in the _redirects file are always processed first, followed by rules in the Netlify configuration file.

The issues here then is the /notes rewrite is inside the netlify.toml while the SPA rewrite is in the _redirects and as the latter takes precedence over the former, the /notes rewrite is never reached. This is because /* redirects all traffic to /index.html.

The solution is to use one of the other, but not both _redirects and netlify.toml. The other thing to note is there is a :splat used with the /notes redirect, but no wildcard (I have incorporated this in the solutions below.)

To use only _redirects set up the file as follows

/notes/*    https://publish.obsidian.md/bearlythinking/:splat    200!
# Put all other redirects/rewrites above this line
/*    /index.html   200

To use only netlify.toml set up the file as follows

[[redirects]]
  from = "/notes/*"
  to = "https://publish.obsidian.md/bearlythinking/:splat"
  status = 200
  force = true

# Put all other redirects/rewrites above this line
[[redirects]]
  from = "/*"
  to = "/index.html"
  status = 200

So the two files are just different ways of handling redirects, got it!

I implemented your solution and got it fixed!

Here’s the final code:

[[redirects]]
  from = "/notes/*"
  to = "https://publish.obsidian.md/bearlythinking/:splat"
  status = 200
  force = true
  
[[redirects]]
  from = "/bearlythinking/*"
  to = "https://publish.obsidian.md/bearlythinking/:splat"
  status = 200
  force = true

[[redirects]]
  from = "/*"
  to = "/index.html"
  status = 200

For some reason, the redirect caused my URLs to look like this:

https://www.bearlythinking.com/bearlythinking/Source+Notes/Books/The+Screwtape+Letters

Instead of effectively replacing publish.obsidian.md/bearlythinking with my custom domain, it only replacd publish.obsidian.md, leaving the subdirectory of /bearlyhinking/ in the URL path.

My current fix is adding the second redirect of the /bearlythinking/, but it seems that this subdirectory is redundant and lengthens the URL unnecessarily. Any thoughts on how to remove it? I’ve looked over the redirect rules a couple of times as well as how wildcards work and I feel like I’m definitely missing something simple here.

Sorry if this is slightly off subject, can move to a new thread if desired.

Thanks a million for your help already though!

Part of the issue I have observed is once you navigate to https://www.bearlythinking.com/notes there is no way back to the homepage. https://www.bearlythinking.com/notes is a mirror of https://publish.obsidian.md/bearlythinking/ (as expected) but as it is a different site, the standard navigation is gone.

Navigating to Articles → Are You Still With Us shows the URL https://www.bearlythinking.com/bearlythinking/Source+Notes/Articles/‘Are+You+Still+With+Us’ (interesting the single quotes are in the URL too :thinking:.) Doing the same from publish.obsidian.md/bearlythinking/ shows the same URL pattern https://publish.obsidian.md/bearlythinking/Source+Notes/Articles/‘Are+You+Still+With+Us’.

This I suspect is the site you are proxying to rather than the proxy itself. Looking at the page source I see

<base href="https://publish.obsidian.md">

along with site configuration data which includes "slug": "bearlythinking". The navigation tree is not a list of links (e.g. <a href=".."> rather each item has a data-path attribute e.g.

<div
  class="tree-item-self is-clickable"
  data-path="Source Notes/Articles/‘Are You Still With Us’.md">
  <div class="tree-item-inner">‘Are You Still With Us’</div>
</div>

When the site URL, slug, and data-path are combined, the URL you (and I) have observed is shown in the address bar. I do not believe there is anything you can do to change this behaviour.

Edit:
On reflection, quite possibly the base doesn’t play any part in the URL, rather as per MDN it is the base for all relative URLs in the document (e.g. scripts.)