Home
Support Forums

Consistent trailing slashes on all URLs

I have a site up on Netlify with pages such as https://stormbrands.co/work and https://stormbrands.co/work/air-partner

I would like these pages so they always end in a trailing slash, i.e. https://stormbrands.co/work/ and https://stormbrands.co/work/air-partner/

I have enabled Asset Optimisation > Pretty URLs. But that doesn’t seem to have done anything.

The site is built with Vue.js so this is what my _redirects file looks like:

/*    /index.html   200

Is it possible to do this with Netlify? I found this which is not what I consider to be a valid fix: https://flaviocopes.com/netlify-fix-trailing-slash-rewrite/

Did you deploy your website again after you enabled the option?

I’ve sinced made new commits to the repo which have been published, yes. Is that what you mean?

Not exactly a solution, but, here’s an another (kind of similar) discussions:

and

The gist being, if you link to a URL without the trailing slash or if the user types the URL without the trailing slash, it would still be served. With Pretty URLs feature, it’s not actually redirecting, instead it’s just modifying links in your HTML to remove .html extension. But since, you have not linked with the .html extension, it is not changing the HTML anymore as it’s already ‘pretty’.

That’s what I understood from that thread. So, if that’s what it is, you might have to update your links to add trailing slashes to them. This would mean, users who use your internal website navigation would only land on pages with the trailing slash, however, if someone removes the trailing slash and tries to access the page, it would still be visible.

OK, thanks. I understand, although quite frustrating given it would be 2 lines of Apache / nginx code. And disappointing given the impact this will have on SEO.

Given the number of threads there are on this community about the topic, surely Netlify can find a solution?

There’s a bit of work you can do on your end to fix SEO too. Canonical links can help you with that. Surely this isn’t a solution to the problem, but, for the time being, you can work with that. More about it here: Improved SEO with canonical link headers

Hi there. I know it’s only been 1 month, but I wanted to find out if there has been any solution to this problem. I’m getting a lot of criticism from my SEO agency about this. We’ve implemented the fix aforementioned in https://flaviocopes.com/netlify-fix-trailing-slash-rewrite/ but they are demanding 301 redirects.

The only thing I can think of at the moment is to move my site to a traditional nginx / Apache host. Please can you help!?

I don’t believe we have anything better than that for those specific requirements today, @sel. Sorry I don’t have better news for you!

Hey @sel :wave:t2:

I just wrote up a pretty comprehensive article walking through the steps required to get trailing slashes working everywhere. Might be worth a read for you:

Otherwise, I checked out your site and, assuming you still have “Pretty URLs” still enabled for your site, I think what I can see from some CLI HTTP requests is that you’re missing a nesting layer. In canonical / historical web parlance, a URL’s path with a trailing slash represented a directory and a path without represented a document. The “Pretty URLs” feature helps accommodate that history but still adheres to it. If you have a document, /work/equall.html, Pretty URLs will convert it to /work/equall but not add a trailing slash because it’s a document, not a directory.

If instead you rename that file index.html and nest it inside a named folder, Pretty URLs will enforce a slash and treat it like a directory. E.g. change /work/equall.html to /work/equall/index.html. In this case, Pretty URLs is always going to enforce a trailing slash because the user is looking at a directory, not a single document.

I hope that makes sense and helps. No _redirects or anything needed!


Jon