Skip to content

Commit 3850549

Browse files
committed
Fix redirection to url without trailing slashes not considering about config urlpath
1 parent 4675219 commit 3850549

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

app.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,14 @@ app.use(function(req, res, next) {
182182
next();
183183
});
184184

185-
// redirect url with trailing slashes
185+
// redirect url without trailing slashes
186186
app.use(function(req, res, next) {
187187
if ("GET" == req.method && req.path.substr(-1) == '/' && req.path.length > 1) {
188188
var query = req.url.slice(req.path.length);
189-
res.redirect(301, config.serverurl + req.path.slice(0, -1) + query);
189+
var urlpath = req.path.slice(0, -1);
190+
var serverurl = config.serverurl;
191+
if (config.urlpath) serverurl = serverurl.slice(0, -(config.urlpath.length + 1));
192+
res.redirect(301, serverurl + urlpath + query);
190193
} else {
191194
next();
192195
}

0 commit comments

Comments
 (0)