Many webmasters want to know whether to include a trailing slash (/) at the end of URLs.
This has potential implications for SEO because search engines like Google don’t always see different URL structures as equivalent.
Here’s what Google representative John Mu has said about trailing slashes:
I noticed there was some confusion around trailing slashes on URLs, so I hope this helps. tl;dr: slash on root/hostname=doesn't matter; slash elsewhere=does matter (they're different URLs) pic.twitter.com/qjKebMa8V8
— 🍌 John 🍌 (@JohnMu) December 19, 2017
The short answer is that the trailing slash does not matter for your root domain or subdomain. Google sees the two as equivalent.
But trailing slashes do matter for everything else because Google sees the two versions (one with a trailing slash and one without) as being different URLs.
The trailing slash matters for most URLs
Conventionally, a trailing slash (/) at the end of a URL meant that the URL was a folder or directory.
At the same time, a URL without a trailing slash at the end used to mean that the URL was a file.
However, this isn’t how many websites are structured today. Many sites with folders serve the same content whether the URL ends in a trailing slash or not.
In this way, the two URLs below provide the exact same content:
For example, this is usually the case with WordPress sites. They deliver the same content with and without the trailing slash.
In some cases, the non-trailing slash and trailing slash version don’t redirect to the correct version. This can cause issues with crawling and duplicate content.
In this case, Google recommends that you redirect from one to the other and use that version everywhere.
If you decide to include the trailing slash (like I do), then you should set up a 301 redirect from the non-trailing slash version to the trailing slash version.
File names should not end in a trailing slash
A trailing slash should not be added for URLs that end in a file name, such as .html, .php, .aspx, .txt, .pdf or .jpg.
If you force a trailing slash on a file name, then that will cause the browser to think it is a folder and will result in a 404 error message.
The trailing slash on the root domain does not matter
It does not matter if your root or hostname has a trailing slash or not.
Your web browser and Google see the see these two URLs as equivalent:
However, different browsers may sometimes show the URL as either having a trailing slash or not when you look at the address bar.
In some cases, the URL displays without a trailing slash in the address bar. But when you copy and paste it, then it shows with the trailing slash.
This is normal. The browser is just hiding the trailing slash from the address bar to make it look better.
Be consistent and redirect from one to the other
It can cause problems with duplicate content and crawl efficiency if your pages are accessible with and without a trailing slash.
That’s because Google sees the two different URLs as unique and may index both of them in search.
For this reason, you should redirect from one to the other using a 301 redirect.
In addition, you should always use your preferred version when doing internal linking, in your sitemap, in your rel canonical tags, etc.
Here’s another tweet from Google’s John Mu on this:
The best solution is to be consistent and only use one version of a URL. Link to that version, redirect to it, use it in sitemaps, use it for rel-canonical, etc.
— 🍌 John 🍌 (@JohnMu) July 11, 2019
In other words, Google does not care which version you choose (trailing slash or not). But they want you to choose one version and use it consistently.
If you are in doubt whether to use a trailing slash or not, then having the trailing slash is slightly better because it is more common.
Trailing slashes in WordPress URLs
WordPress uses a directory structure, so it makes more sense to include trailing slashes at the end of page URLs.
In fact, this is the default behavior in WordPress.
If you want to change it from one to the other, then you can do that easily in the WordPress permalinks settings.
Go to your WordPress Dashboard -> Settings -> Permalinks.
If you choose a “Custom Structure” for your permalinks, then you can either include or remove the trailing slash at the end.
Your options are:
/%postname%/ -- Has a trailing slash at the end /%postname% -- No trailing slash
If you change it, then WordPress will automatically enforce your chosen version. It will 301 redirect to it, change internal links and rel canonical tags, update the sitemap, etc.
If you do this and the redirect doesn’t work, then you should contact your web hosting company for help. It is not recommended to mess with server configuration files like .htaccess unless you really know what you are doing.
Which is better to use? It depends
If you have a website that is already established, then you should probably use whatever your site is using today.
In other words, if your site’s URLs do or don’t use a trailing slash, then stick to that approach. There is certainly no SEO benefit to switching.
On the other hand, if you are starting a new site today, then it is probably better to include a trailing slash simply because this is more common and more likely to be expected by users.
Whichever one you choose, it makes sense to be ultra-consistent and have 301 redirects from one to the other.
If you have problems with the redirects or don’t know how to add them, then I recommend you contact your web hosting company’s technical support and ask them to set it up for you.
On my WordPress sites, I use trailing slashes at the end of URLs. I also 301 redirect to the trailing slash version and use that everywhere — in sitemaps, links and rel canonical tags.
At the end of the day, it doesn’t matter which one you choose, but it is important to be consistent.