This is a multi-site problem. I have a lot of sites with .htaccess files with multiple line similar to:
rewriterule ^(page-one|page-two|page-three)/?$ /index.php?page=$1 [L]
This means that both www.domain.com/page-one and www.domain.com/page-one/ will both load www.domain.com/index.php?page=page-one
However I'm always told that it is good SEO practice to make sure you use only one URL per page so what I'd like to do make www.domain.com/page-one to redirect to www.domain.com/page-one/ via the .htaccess file.
Please note the answer I'm NOT looking for is to remove the ?$ from the end of the line as that will just cause www.domain.com/page-one to become a 404 link.
How to add a trailing slash to URLs. One of the easiest and most convenient way to add or enforce trailing slashes on URLs is by RewriteRule directive. You can write a single rule in your htaccess file that will apply to all URLs without a trailing slash.
To do so, go to the “Settings -> Permalinks” section and, depending on your situation, either add or delete the last slash. 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.
Email Subscription. A trailing slash is a forward slash (“/”) placed at the end of a URL such as domain.com/ or domain.com/page/. The trailing slash is generally used to distinguish a directory which has the trailing slash from a file that does not have the trailing slash.
Use the String. replace() method to remove a trailing slash from a string, e.g. str. replace(/\/+$/, '') .
Here's a snippet to force everything to end with a slash
rewritecond %{REQUEST_FILENAME} !-f
rewritecond %{REQUEST_URI} !(.*)/$
rewriterule ^(.*)$ http://%{HTTP_HOST}/$1/ [L,R=301]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With