A tiny code snippet can ensure all directory URLs are forced to contain a trailing slash. In WP Permalinks you can make this the default link.
Examples
Here are a couple of examples showing the before-and-after state of your directory links, with and without trailing slashes.
No Trailing Slash
No matter the directory level, these links exampled end without a trailing slash. Before WordPress, this was a development standard where it denoted that all links without slashes at the end meant there were no link levels beyond that on the website.
https://yourwebsite.com/root-folder-page-title https://yourwebsite.com/category/page-title https://yourwebsite.com/category/parent/child-category
With Trailing Slash
Once content management systems like WordPress became standard for developers, the default then became the CMS default, which was adding a trailing slash to every link.
https://yourwebsite.com/root-folder-page-title/ https://yourwebsite.com/category/page-title/ https://yourwebsite.com/category/parent/child-category/
Once you add the code snippet below, no matter if you visitors or search bot visit a page without trailing slash, it will automatically have a trailing slash appended.
Code Snippet
When adding the code below to your .htacces file, you will ensure that all directory requests include a trailing slash. It also safeguards against adding the trailing slash if a file is requested. i.e. no trailing slash would be added to file.php, file.css, etc.
Apache# Force trailing slash
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_URI} /+[^\.]+$
RewriteRule ^(.+[^/])$ %{REQUEST_URI}/ [R=301,L]
</IfModule>
Once the .htacces rule is in place, all directory URL requests will be checked for a trailing slash. If one does not exist and the URL is verified as NOT being a file, a trailing slash is then appended to the link.
WP Permalinks
To set your WordPress website to contain a trailing slash by default, just ensure your post permalink has a trailing slash at the end of it.
/%postname%/
Warning: This will only solve the missing trailing slash issue on posts and pages that still exist. For any others that have been deleted or renamed in the past, you will still need to use the htacess code snippet to get rid of them in your 404 logs.
404 Errors
Many of the URLs with missing trailing slashes in your 404 logs can be blamed on search bots looking for pages that no longer exist. The main culprits are Bing, Criteo, Grapeshot, and Admantx, with the Bingbot being notorious for never giving up on links even years after it’s been removed from a website.
So, if a page once existed, even for just 10 minutes and a search engine bot indexed it, you could see 404 errors in your logs for years to come in links with and without the trailing slash.
Solution
To get rid of the second problem of search bots looking for pages and posts without a trailing, just add this code snippet to your .htacces file.
To fix the first problem, of a page that did exist that contained a trailing slash you still either have to redirect it to its corresponding replacement link or mark it as 410 gone.
410 Gone
For replacement links, you generally only want to do this for links that still have active backlinks. If you don’t do this, search bots will still be looking to see if the page has been resurrected 5 years later.
If you 410 Gone a backlink you’ll lose the link juice it once gave, so always keep your page redirection live while their backlinks still exist.
If a page has no backlinks and its replacement has already been swapped in search engine listing, then you need to 410 Gone this link. If not, a search engine bot will just hammer your constantly seeing if the redirection link still works which causes unnecessary server load and bandwidth usage.