Does redirects.json work with Ghost REST API?

I’m looking into setting up redirects using the redirects.json feature:
https://docs.ghost.org/v1/docs/redirects

Tested around but could not get it working. Should I expect the API request URL to redirect? Or does this feature only work when using a Ghost template vs. the REST API?

Here’s my redirects.json:

[
    {
        "from": "the-future-of-public-finance-is-coming",
        "to": "lets-restart-the-hidden-economic-engine",
        "permanent": true
    }
]

Requesting this URL in a browser:
https://neighborly.com/learn/the-future-of-public-finance-is-coming

Still yields the following API request, which 404s:
https://neighborly.com/learn/ghost/api/v0.1/posts/slug/the-future-of-public-finance-is-coming/?...client_secret_info

Ideal scenario would be to redirect the browser to the new page:

Less ideal but workable scenario would be that the API request redirects the slug:
https://neighborly.com/learn/ghost/api/v0.1/posts/slug/lets-restart-the-hidden-economic-engine/?...client_secret_info

Thanks!

Ghost’s redirects.json does not affect the API at all, it only deals with URLs (not slugs) and will redirect a request coming in to the front-end not the API.

Eg. redirects.json:

[
    {
       "from": "/old-post/",
       "to": "/new-post/",
       "permanent": true
    }
]

myblog.com/old-post/ → (301) → myblog.com/new-post/

1 Like

The docs cover typical use-cases:

https://docs.ghost.org/docs/redirects

Ah, bummer. Thanks @Kevin. Given that redirects.json does not affect the API at all, I’ll solve this with NGINX.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.