How to rewrite a trailing slash for SEO purposes

in Nginx configuration

Search engines don’t like duplicate content. To rewrite trailing slashes some nginx configuration is required.
If you rewrite all urls, some issues rise with the Magento backend admin and some other endpoints.

To resolve this issue, use the following snippet to strip all trailing slashes and add this to your /data/web/nginx/server.rewrites:

if ($uri !~ /admin|/webpos) {
    rewrite ^/(.*)/$ /$1 permanent;

Or this snippet if you want to add trailing slashes:

if ($uri !~ /admin|/webpos) {
    rewrite ^/(.*)/$ /$1/ permanent;

Replace /admin and /webpos with urls that should not be rewritten in a regex of urls separated by pipes (|).