Trailing slashes and SEO

Trailing slashes and SEO - what is the issue?

A trailing slash is a slash you sometimes see at the end of a URL: (without trailing slash) (with trailing slash)

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.

Duplicate content issue

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.

Google scans and ranks individual URLs at the most basic level. This means they must be one-of-a-kind. If the same page can be accessed via two separate URLs, we have a problem with duplicate content. It may appear nearly identical, and it may function flawlessly, but it is not optimized for search.

Link equity issue

Having two copies of the same page live on two separate URLs confuses anyone attempting to link to your page. Is the trailing slash used or not? A decision must be made. If half of the individuals link to the URL with a trailing slash and the other half don't, your link equity is split in half.

Crawl budget issue

Google does not crawl your entire website on a daily basis. A crawl budget dictates how much of your website is explored and indexed. This isn't a major concern for small sites; anything under 100 pages is likely to be indexed. 

However, for larger sites with thousands of pages, it becomes yet another area that must be optimized. A lot of factors influence the size of your website's crawl budget, including:

  • Website size: How many URLs are there to crawl in total.
  • Website's health: How many errors Google finds.
  • Website links: How many backlinks you have, and which URLs they link to.

Duplicate material created by incorrectly managed trailing slashes allows Google to crawl numerous copies of the same page unnecessarily. While you are unlikely to be penalized manually for this type of duplicate information, it does make the search engine's job significantly more harder. Ignoring duplicate material caused by trailing slashes is the polar opposite of SEO.

User experience issues

Whether or not a URL has a trailing slash, it is regarded as a distinct and individual web page. If the same URL appears with and without a trailing slash, the content on the page may be technically different. The page is identical in most trailing slash scenarios, but given the number of individuals who work on websites, all making adjustments and sometimes injecting custom code, you can't ensure they'll stay the same forever.

The longer two separate URLs remain for the same page, the more likely their respective content will change. Consider how perplexing it would be for a user to come across two versions of your website, or to follow a link from an external site to an older version of your page. Ignoring trailing slash issues only complicates matters for everyone: the user, search engines, and anybody else that interacts with your website.

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: (200) (301 redirect) ?

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.