How can we help you today?

How to Rewrite a Trailing Slash for SEO Purposes

Created by: Sophie van Vrijberghe de Coningh

Modified on: Mon, 10 Feb, 2020 at 10:47 AM


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 (|).

S
Sophie is the author of this solution article.

Did you find it helpful? Yes No

Send feedback
Sorry we couldn't be helpful. Help us improve this article with your feedback.