Using an Nginx Rewrite to Add Trailing Slashes to Your URLs

Keeps things SEO-friendly

rewrite ^([^.]*[^/])$ $1/ permanent;

Add to your server block. This line will add a trailing slash o the end of your URLs, as long as they don’t contain a period (for things like static assets), and if it does not already have a trailing slash.

This is a handy way to improve SEO by redirecting all non-trailing slash links to ones with the slash. Because yes, a single slash can cause duplicate content issues. Use this method if you can’t mange to programmatically add canonical URLs throughout your site; you should be well on your way to better search engine optimization.