.htaccess Rewrite to Force Trailing Slash at the end

A slightly more robust answer, based on the answer above:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)([^/])$        /$1$2/ [L,R=301]

The RewriteCond will check to make sure there’s no files with that name, and if not, perform the RewriteRule. More future-proof than having a manual list of extensions!

Leave a Comment