Redirects using placeholders and colon (:) character

I am having trouble setting up placeholder redirects so https://data.destinysets.com/i/InventoryItem:1996008488 does an internal rewrite to
https://data.destinysets.com/link_previews/InventoryItem:1996008488

I’m trying to set up pre-rendered pages that contain meta tags for Twitter Cards, Slack Previews, etc. I’m able to use a build script to render the pages and they’re served correctly as expected. What I’m having trouble doing is setting up the redirects so these pages are served correctly. They work locally when using netlify dev, but not in Netlify’s live environment.

The site is a single page app, and urls follow the format of https://data.destinysets.com/i/[name]:[id]. Additionally, the URLs can also represent a hierarchy of items, which would look like https://data.destinysets.com/i/[name]:[id]/[name2]:[id2]/[name3]:[id3]/[...etc] (for example, Destiny Data Explorer). For the purpose of this issue at the moment, I’m only concerned about the first form, with just one item in the URL.

My _redirects is

/*    /index.html   200
/i/:item /link_previews/:item.html 200

When I navigate to Destiny Data Explorer I would expect to see the content of Destiny Data Explorer, with multiple <meta tags in the <head>.

Is this supported by Netlify? Am I missing something?

Hi Josh,

In our system, the redirects engine isn’t really using regular expressions. In the case of placeholders like :slug or *, things work best when it is the entire pathname component, so /i/* would match "/i/InventoryItem:1996008488`.

I know that probably isn’t ideal for your use case, but it’s what our system can handle. You could always use some client-side javascript to help out in breaking things up and then do a 301 redirect from the browser to work around it.

Okay, thanks for this! I’ll see what I can do :slight_smile: