Title photo
frugal technology, simple living and guerrilla large-appliance repair
Tue, 30 Jan 2018

Use an .htaccess rewrite to force trailing slashes at the end of URLs

I'm looking into this very thing -- using .htaccess to force trailing slashes at the end of URLs requested on the Apache web server.

Stack Overflow may have the answer:

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

As SO user jeffbyrnes says,

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!

I don't have time right now to hack this onto a server, but I will for sure be giving it a try.