Trailing Slashes in WordPress Permalinks

The trailing slash is an often-overlooked element, but if not handled properly, trailing slash settings might cause duplicate content SEO problems.

Despite the fact that trailing slashes can affect SEO, WordPress website owners often do not know how to manage whether or not they are included to their permalinks.

In this article, you will discover why ignoring this may result in a "duplicated content" issue, as well as how to force one version using WordPress built-in settings and .htaccess file.

What Are the Trailing Slashes?

Generally speaking, slashes in URLs are used to distinguish between files and directories/folders. Separating directories and subdirectories in a URL allows for hierarchical content organization.

Slashes in URL

For example, a URL like the one presented above uses slashes to show the product is located in the "products" folder, which is inside the "olive" and "greece" subfolders.

The forward slash (highlighted in red) at the end of a website address is called a trailing slash. By design, URLs for folders or directories are meant to end with a slash. This helps distinguish them from single file URLs like images, which typically end with a file extension like .jpg or .css instead of a slash.

However, CMS such as WordPress can dynamically change URLs on the fly. So this rule about trailing slashes is not always followed as strictly as it used to be. The CMS might add or remove that slash depending on what helps people find the page more easily. So both folder URLs with a trailing slash and single file URLs without one can work fine nowadays.

Does Trailing Slash Matter for SEO?

Considering the possible effect on SEO that trailing slashes in WordPress permalinks might have, it is surprising how little information there is on the subject. Happily, there is nothing complicated or hard to understand here.

Depending on the permalinks settings, trailing slashes may be automatically appended or removed from all URL addresses. Take a close look at these URLs below. Both look identical, but only at first glance. The first URL varies from the second in that it finishes with a slash.

Trailing slash in WordPress URL (example)
The single slash character (/) is what sets the URLs apart.

Most visitors to your website likely will not notice whether URLs include a trailing slash or not. It might, however, make a significant difference for search engine crawlers. Search bots may consider the second variant of URL as a duplicate if they can reach the same page via separate URLs.

To sum up, for SEO, even details like this can make a big difference. Years ago, John Mueller, one of most well-known Google experts, emphasized on Twitter how important it is to be consistent with trailing slashes.

Trailing Slash Redirect

Regardless of whether you decide to include them in the URL or not, you need ensure that all of the URLs follow your choice and use the same settings. Redirecting non-trailing slash URLs to trailing slash URLs or vice versa is an effective way to ensure this.

Canonical URLs are handled by WordPress to some extent, however the functionality may vary based on your settings, plugins, and WordPress version. However, the canonical redirect can also be affected by factors such as your server's setup, caching systems, and additional plugins.

How to use the trailing slash redirect for WordPress permalinks?

Even if you do not know how to code, you can use Permalink Manager to force the preferable trailing-slashes mode with the "trailing slash redirect" function.

Google Analytics Reports and Trailing Slashes Inconsistency

In addition, if your website handles trailing slashes inconsistently, it is possible that duplicate URLs may appear in your Google Analytics results. While past statistics cannot be fixed, you can adjust the future collection of data to avoid this issue.

Google Analytics dashboard

Thankfully, it can be avoided with a straightforward fix. The first option is to apply the URL filters that are included into Google Analytics. There are numerous articles, such as this one, that explain how to use them.

However, forcing one version of the URL via a "301" redirect directly on your server is the most reliable and recommended method. You may accomplish this by using .htaccess code or a third-party plugin like Permalink Manager.

How to Change Trailing Slash Settings in WordPress?

There is a simple way to keep your trailing slash settings consistent without having to install extra plugins. Most WordPress users and developers are unaware that the trailing slash mode is determined by whether a slash appears at the end of the "Custom Sturcture" field.

You may easily adjust it using the built-in permalink settings. Even users who are unfamiliar with WordPress should find this simple. To do so, go to the "Settings -> Permalinks" section and, depending on your situation, either add or delete the last slash.

"Custom Structure" field affects your trailing slash mode.
The "Custom Structure" field ends with a slash, so all other WordPress URLs will have the trailing slash. Likewise, if it is not present there, the slash will be missing in your website's URLs.

How to Add Trailing Slashes?

Please see the screenshot below to see how to add trailing slashes to WordPress permalinks using only the built-in settings. Because the structure field ends in a slash (see red arrow), WordPress will append the slash to all URLs.

Add trailing slash

How to Remove Trailing Slashes?

The steps are similar to the previous section. To remove the trailing slash from WordPress permalinks, simply ensure the "Custom Structure" field does not end with a forward slash.

Remove trailing slash from WordPress permalinks

Permalink Manager may be a useful solution to modify trailing slashes settings if you do not have any technical skills or simply do not want to bother with coding. To put it in a nutshell, you may use the plugin to either add or delete the slashes automatically from all WordPress permalinks.

The plugin dynamically filters $wp rewrite->use_trailing_slashes property, therefore all WordPress permalinks (not only the ones filtered with Permalink Manager) will be affected. Of course, this also applies to meta tags (canonical URLs) and sitemaps built by third-party tools like Yoast SEO or RankMath.

You can get back to original mode at any moment! To revert the changes please select "Use default settings" in Permalink Manager settings.

"Trailing slashes" settings in Permalink Manager admin panel.

How to Force Trailing Slash Mode With Redirect?

A canonical redirect is the quickest solution to address duplicate content issues caused by trailing slashes. If you choose to implement the 301 redirect, both users and search engine crawlers will always be sent to to one of two URL versions: with or without slashes.

If you do not know how to code, Permalink Manager may help you in using the redirect. To make it work and force your chosen slashes configuration, enable the "Trailing slashes redirect" option in the plugin settings.

Trailing slash redirect checkbox
To activate the redirect, please turn on "Trailing slashes redirect" option in "Settings -> Redirect settings" panel.

Trailing Slashes and Cache Plugins

Certain caching plugins may cause the Permalink Manager trailing slash redirect to fail. It happens, for example, when you use the WP Rocket plugin. This is because cache plugins will utilize the same cache container for the URL with and without the trailing slash.

As a consequence, Permalink Manager will be unable to determine if the URL has a slash or not due to the cache. To fix this problem, add one of the following snippets to the beginning of the .htaccess file.

If you need to remove the trailing slashes from all URLs, use the following code:

# A. Remove trailing slashes
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]

The code to force the trailing slashes is a little more complicated, as we need to exclude filenames and URLs with query parameters.

# B. Force trailing slashes
RewriteEngine on
# Exclude files and directories under "wp-content", "wp-admin", "wp-json" and URLs with query parameters
RewriteCond %{REQUEST_URI} !^/?wp-(admin|json|content)
RewriteCond %{QUERY_STRING} ^$
# This rule should not be applied to URLs that look like filenames and already end with a trailing slash
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
# Check if the request URI does not end with a slash
RewriteCond %{REQUEST_URI} !(.+)/$
# If all conditions are met, redirect to the same URI with a trailing slash
RewriteRule (.*) %{REQUEST_URI}/ [R=301,L]
Go up