url rewriting - Rewrite PHP URL for Node.js -
i need rewrite url node:
/single.php?articleid=123 to this:
/article/123 this because company work printed out qr codes said url old software. software got rewritten in node, no qr code works anymore. how can support old url node? tried setting route it:
app.get('/single.php?articleid=:id', log.logrequest, auth.checkauth, function (request, reponse) { response.send(request.params.id); }); but responds this:
cannot /single.php?articleid=12 any ideas? thanks.
express routes paths, should able route single.php , articleid req.query.
app.get('/single.php', log.logrequest, auth.checkauth, function (request, reponse) { response.send(request.query.articleid); }); if want require query parameter route, can create custom middleware it:
function requirearticleid(req, res, next) { if ('articleid' in req.query) { next(); } else { next('route'); } } app.get('/single.php', requirearticleid, ..., function (request, reponse) { // ... }); next('route') discussed under application routing.
Comments
Post a Comment