Skip to content

Astro, fix .md in links

Using Obsidian to edit my Markdown files, I’ve started to link lessons using Obsidian’s own internal linking.

It’s great because with Obsidian link tracking I can move a file around, change folder or filename, and links don’t break.

Links however use a .md extension, since we’re linking markdown files here.

[3-absolute-positioning](../css-positioning/3-absolute-positioning.md)

So since I’m using Astro, links don’t work as they point to a URL ending with .md.

I found this rehype plugin for Astro: https://github.com/vernak2539/astro-rehype-relative-markdown-links

It fixes this exact problem and I’m so grateful this exists, but didn’t (at the time of writing) install on Astro 3, required Astro 2. Maybe now it’s updated.

Anyway since it’s a single file I copied the file locally and imported in my Astro config.

Only thing I noticed is, maybe because I use content collections, my content collection path was prepended to URLs now, so I hardcoded a little custom fix in the code that only works in my use case, but well, job done.


download all my books for free

  • javascript handbook
  • typescript handbook
  • css handbook
  • node.js handbook
  • astro handbook
  • html handbook
  • next.js pages router handbook
  • alpine.js handbook
  • htmx handbook
  • react handbook
  • sql handbook
  • git cheat sheet
  • laravel handbook
  • express handbook
  • swift handbook
  • go handbook
  • php handbook
  • python handbook
  • cli handbook
  • c handbook

subscribe to my newsletter to get them

Terms: by subscribing to the newsletter you agree the following terms and conditions and privacy policy. The aim of the newsletter is to keep you up to date about new tutorials, new book releases or courses organized by Flavio. If you wish to unsubscribe from the newsletter, you can click the unsubscribe link that's present at the bottom of each email, anytime. I will not communicate/spread/publish or otherwise give away your address. Your email address is the only personal information collected, and it's only collected for the primary purpose of keeping you informed through the newsletter. It's stored in a secure server based in the EU. You can contact Flavio by emailing flavio@flaviocopes.com. These terms and conditions are governed by the laws in force in Italy and you unconditionally submit to the jurisdiction of the courts of Italy.

Related posts about astro: