I am using Node.js and Express and I have the following routing :
app.get(\'/\', function(req,res){
locals.date = new Date().toLocaleDateString();
r
One liner:
router.get('\\S+\/$', function (req, res) {
return res.redirect(301, req.path.slice(0, -1) + req.url.slice(req.path.length));
});
This will only catch the url's that need to be redirected, and ignore the others.
Example results:
/ ==> /
/a ==> /a
/a/ ==> /a
/a/b ==> /a/b
/a/b/ ==> /a/b
/a/b/?c=d ==> /a/b?c=d