Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
MKorostoff opened this issue May 26, 2019 · 1 comment
Open

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

MKorostoff opened this issue May 26, 2019 · 1 comment

Comments

@MKorostoff
Copy link

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
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants