Contents
- Trailing slashes and SEO - what is the issue?
- Should I add or remove a trailing slash
- The history of trailing slashes
- Use the same variant across your site
- Removing trailing slashes in .htaccess (Apache)
- Adding trailing slashes in .htaccess (Apache)
- Removing trailing slashes in Nginx
- Adding trailing slashes in Nginx
- SiteGuru check
Trailing slashes and SEO - what is the issue?
A trailing slash is a slash you sometimes see at the end of a URL:
https://www.example.com/folder/
You may or may not add a slash at the end of a URL - both options are fine. It’s important to realize that search engines consider the URL with and without the slash as two different pages. This has serious implications for SEO.
If a page works with and without the trailing slash, you have exactly the same page on different URLs. That’s duplicate content, and you now have two URLs competing for the same keywords in Google.
Should I add or remove a trailing slash
From an SEO perspective, it doesn’t matter whether a URL does or doesn’t have a trailing slash. Google announced back in 2010 that it doesn’t matter unless you don’t have both variants returning a status code 200 (OK). Instead, return a 200 status code on your preferred variant, and a 301 redirect to the preferred variant for the other:
https://www.example.com/folder (200)
https://www.example.com/folder/ (301 redirect) ? https://www.example.com/folder
The history of trailing slashes
Why do both variants exist anyway? Historically, a URL with a trailing slash was a directory, and a URL without it was a file. Currently, that differentiation is no longer relevant and you don’t need to consider it.
Use the same variant across your site
Once you’ve decided on the preferred URL variant for your site, make sure you use that variant across your website. Pay special attention to:
- Canonical URLs
- Hreflang tags
- Internal links
- URLs in your sitemap
- Redirects
Not using the right variant in any of these makes crawling your site less efficient. A canonical URL with the wrong variant may cause serious indexing issues.
Removing trailing slashes in .htaccess (Apache)
If you’re using Apache, add the following line to your .htaccess file to redirect all URLs with a trailing slash to the one without:
RewriteRule ^/?(.+)/$ /$1 [R=301,L]
Adding trailing slashes in .htaccess (Apache)
If you rather use a trailing slash in every URL, add this line to your .htaccess file to redirect all traffic to the URL with the trailing slash:
RewriteRule ^(.*)$ $1/ [R=301,L]
Removing trailing slashes in Nginx
To remove trailing slashes on your Nginx server, add the following line to your server configuration:
rewrite ^/(.*)/$ /$1 permanent;
Adding trailing slashes in Nginx
If you opt to use the variant with trailing slashes, add the following line to your server configuration:
rewrite ^([^.]*[^/])$ $1/ permanent;
SiteGuru check
SiteGuru’s SEO audit includes a check for duplicate content on URLs with trailing slashes. If you’re not redirecting one variant to the other, this will be flagged as an issue.