Changing the base_url for posts / Headless CRM

I’ve got ghost working as a headless backend for a next.js site. I’m trying to figure out how to change the “base url” that Ghost uses when return post URLs in the Content API. I tried setting the url field in config, but it seems like that has to match the domain ghost itself is running on, otherwise routing fails (cannot get /).Anybody solve this one? I can replace the ghost domain in my API layer, but prefer that it would show the actual URL in ghost admin frontend as well.

Hey @lasersox :wave:

If I’m understanding you correctly, you have Ghost running on a domain (e.g. ghost.example.com), and you have a next site (e.g. www.example.com), and you’re having issues with the base url being ghost.example.com instead of www.example.com. The fix for this is to set the Admin URL to https://ghost.example.com, and the url to https://www.example.com. Here are the docs for setting the url and the admin url:

Thanks for your reply! You are correct. I’ve tried as you suggest, but it always gives me a “cannot get /” error when loading the ghost.example.com page. Perhaps because I have added a subpath on the url, eg, www.example.com/blog?

If you check our our Eleventy starter you’ll see that I’m swapping out the Ghost URL for a relative path. I’ve found it to be the best way to get a bit more control, and to not cross wires with the Ghost installation:

Thanks David, that makes sense, this will work on the frontend side. I can train the editor / authors how to find the link to their post. Can you verify that it’s not possible to do this on the Ghost side? Would Ghost team be open to this feature? Perhaps I can contribute something?

You could make use of the redirects feature, or use JavaScript, on the Ghost site to redirect links to the Next.js app?

To answer this question specifically if anyone else runs into this, if you set ghost up in a subdirectory, the admin url will also only work in the subdirectory - so

www.example.com/blog - “published” site
ghost.example.com/blog/ghost - Admin interface

1 Like

I will try it. Thanks for the help!

1 Like