ericf / express-slash

Express middleware for people who are anal about trailing slashes.
MIT License
155 stars 13 forks source link

[Request] support redirect to NON-trailing slash #11

Open MKorostoff opened 5 years ago

MKorostoff commented 5 years ago

Currently, this module redirects /mypage to /mypage/. I'd like to do the reverse: redirect /mypage/ to /mypage. I prefer this method because 1) historically a trailing slash signifies a directory and 2) I just like the look of it better. This could be implemented with a config option like:

const slash = require('express-slash')
app.use(slash({mode: 'NOSLASH'}))
gaborszita commented 2 years ago

Your route is probably configured like this:

router.get('/mypage/', function (req, res) {
    res.send('mypage');
});

This tells express (and the library) that your page is at /mypage/ and this is the main url, so it will add a trailing slash whenever somebody goes to the page /mypage.

You should change your route to this:

router.get('/mypage', function (req, res) {
    res.send('mypage');
});

This way express will think about it as /mypage being the main url, so it will redirect /mypage/ to /mypage. This should solve your problem.