Trailing slashes in URLs
A URL that ends with a slash (e.g., example.com/about-us/
) and the same URL but without that slash (e.g., example.com/about-us
), are usually regarded as two different links. That has consequences for visitor analysis and tracking & tracing.
Why?
Why it is important to be consistent with how you write URLs:
- Different URLs for Search Engines: From an SEO perspective, URLs with a trailing slash and without are considered two distinct URLs. For example, https://www.example.com/path and https://www.example.com/path/ are treated as separate URLs by search engines. Some problems with this: Dilution of PageRank + much more objects to take care of (e.g., in sitemaps)
- Loss of click-id's: When a URL with a click-id as parameter is changed from/to the same with/without a trailing slash, the click-id gets lost
- Potential Double Redirect: If you set up a redirect without the trailing slash but your new site's URL structure uses trailing slashes (and has canonical tags set up with the trailing slash or uses redirects to enforce this), then users might experience a double redirect. This can slow down the user experience slightly and is generally something to avoid.
Background
Where this ambiguity concerning trailing URL slashes comes from: By convention, a trailing slash often indicates a directory, whereas no slash might imply a file. However, this distinction has been blurred with modern web practices and systems, as URLs often don't map directly to physical files or directories.
WordPress
By default, WordPress appends a trailing slash (/) to URLs for posts, pages, categories, and tags when using pretty permalinks. WordPress also redirects such links without slashes, to the corresponding link with a slash.
This is actually a quite practical way to check what kinds of links should or shouln't have trailing slashes: Just check in a WordPress site that's not specifically modified in this regard (see remarks about WP Rocket elsewhere).
For example:
- A post might have the URL:
https://www.example.com/my-post/
- A category might be accessed via:
https://www.example.com/category/news/
Exceptions
However, there are some exceptions:
Exception | Notes |
---|---|
Root URL |
|
Files |
|
URLs with query parameters |
|
URLs with local anchors |
|
Other protocols? |
|
If you're setting up redirects for a WordPress site, you should typically include the trailing slash in the destination URL to match the default behavior of WordPress. This ensures a smooth user experience and helps prevent any potential SEO issues.
Checklist
Always end URLs with a slash, however...
- Not for parameter URLs
- Not for URLs with local anchors
- Not for links to files
- Not for root URLs
- Check for links to other protocols.
WP Rocket
In 2023.10, we found out that WP Rocket thwarts this default behaviour of WordPress, and doesn't append slashes. See WP Rocket & Redirects for details.
See also
Sources
- https://stackoverflow.com/questions/54536401/add-trailing-slashes-in-wordpress-multisite-without-damaging-the-admin-interface - Nice, but not relevant
- https://developer.wordpress.org/reference/functions/trailingslashit/ - Nice but not relevant
- https://webmasters.stackexchange.com/questions/118750/how-to-remove-trailing-slash-from-my-root-url-in-htaccess - Nice but not relevant
- https://docs.wp-rocket.me/article/131-redirection-to-enforce-trailing-slash-on-urls - Relevant!