Code Bytes
Add a trailing slash only where your routes expect one
Normalise selected page URLs with Apache without adding slashes to assets, APIs, unknown paths or payment callbacks.
Both /about and /about/ can be valid URL designs. Consistency matters more than choosing one universally. A blanket rule that appends / to every non-file request can break APIs, signed URLs and application routing.
Prefer the application's canonical URL setting
For WordPress, check the permalink configuration before adding another rewrite layer. If a small static site needs a server-level rule, an explicit page allowlist is easier to verify than a pattern matching every possible URL.
This Apache 2.4 root .htaccess example normalises three known pages:
RewriteEngine On
RewriteCond %{REQUEST_METHOD} ^(?:GET|HEAD)$
RewriteRule ^(about|services|work)$ https://example.com/$1/ [R=302,L]
Replace the hostname and route names with your actual canonical routes. There is deliberately no rule for assets, unknown slugs, Contact submissions or Pay callbacks. Existing query strings are preserved.
After checking each mapping, change 302 to 301 if this is a permanent canonical decision. Put the rule before a front controller's catch-all rule, not inside a CMS-managed block that may be regenerated.
Check all three outcomes
/about should redirect once to /about/. /about/ should load directly. An unrelated /does-not-exist should remain a genuine 404. Also check a real stylesheet and a URL with a query string; neither should end up at an invented slash-suffixed filename.
Update internal links, canonical tags and the sitemap to use the chosen format. A redirect should handle old incoming links, not make every click on your own site take an unnecessary extra hop. Nginx does not use .htaccess; configure this in the layer that actually owns your routing.
References: Apache rewrite rules and WordPress permalink guidance.
Original version4 May 2014
Kept here for reference and earlier links. The updated guide above is the recommended starting point; older code may depend on retired services or different software versions.
Have you ever wanted a web page to act like a directory?
Eg, have /about, but want it to seem as though /about is a directory, such as: /about/
With the following added to your htaccess it's simple:
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*).htm
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://www.YOURWEBSITEHERE.com/$1/ [L,R=301]
Keep exploring