You can make a character optional by appending the ?
quantifier to it like this:
RewriteRule ^([^/]+)/?$ $1/index.html
Now both /foobar
and /foobar/
would be rewritten to /foobar/index.html
.
But it would be better if you use just one spelling, with or without the trailing slash, and redirect the other one:
# remove trailing slash
RewriteRule (.+)/$ /$1 [L,R=301]
# add trailing slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .*[^/]$ /$1/ [L,R=301]
These rules either remove or add a missing trailing slash and do a permanent redirect.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…