Pages don't resolve without trailing slash

The article pages on my blog don’t resolve if there is no trailing slash at the end of the URL. E.g. , Your first performance budget with Lighthouse versus Your first performance budget with Lighthouse

Ghost redirects all URL’s without a trailing slash to one with a trailing slash.

This is by design, as having only one url per page is better for SEO.

Hi Fabien! I understand that, my issue is that the redirect isn’t working. This is what people see when they go visit a URL without the trailing slash:

Oh how strange! I visited both links when you posted and they worked fine, but now I see the same thing in your screenshot.

When I do a hard refresh however it does load/redirect correctly :confused:

I’ve seen this behavior before when using service workers and they get corrupted - are you using a service worker on your site?

Ah okay! Yes I am using a service worker, and I thought it could be related but my implementation is similar to what I’ve used on other sites. I guess I need to figure out how to handle the redirects via the service worker as well. If there’s any documentation you have on this, that would be great!

I fixed it!

1 Like

Wooo, glad you got it working!!

How did you solve it in the end, I’d be super interested to hear :relaxed:

Thanks! :tada:

Basically you were correct that the service worker was corrupted. I had pushed an update to the service worker over a month ago that had a fault in it, but when I updated the file to fix it a few weeks ago, the new version was never loaded.

I discovered yesterday that this was because Ghost has a pretty intense caching system, and the new versions of files aren’t loaded unless they have a query parameter on the file name. So, I fixed the issue by registering my service worker like this:

navigator.serviceWorker.register("/sw.js?refresh=true", {scope: "/"})

I think this will work even when I update the file again, but I may have to switch to using a versioned number instead if it doesn’t.


Awesome :slight_smile:

If you find/think of something that can be improved with regards to caching and using service workers in Ghost, do let us know, or even open a PR :angel:!

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