diff --git a/lib/middleware.js b/lib/middleware.js index eb96dd1..f9e4d99 100644 --- a/lib/middleware.js +++ b/lib/middleware.js @@ -3,12 +3,13 @@ // Creates new middleware using provided options function create (rules) { return function redirectRoute (req, res, next) { - const foundRule = rules.find(o => o.from.test(req.url)) + const decodedBaseUrl = decodeURI(req.url) + const foundRule = rules.find(o => o.from.test(decodedBaseUrl)) if (!foundRule) { return next() } - const toUrl = req.url.replace(foundRule.from, foundRule.to) + const toUrl = decodedBaseUrl.replace(foundRule.from, foundRule.to) res.statusCode = foundRule.statusCode || 302 res.setHeader('Location', toUrl)