Wednesday, 15 March 2017

Rerun routes with new URL

I have a small web server which serves as an optimizer for old URLs, it matches old urls and redirects to new nicer SEO-optimized urls.

One of the url is something like:

login.php?return=http://example.com/index.php?page=protected_page

Now after optimizing the service, http://example.com/index.php?page=protected_page is now just /page/protected_page/ and has the authentication inside, so naturally i put a match like

'login.php': function(req, res, next) {
  if (req.query.return) {
    res.redirect(req.query.return);
  }
}
'index.php': function(req, res, next) {
  if (req.query.page) {
    // redirect to proper seo page without index.php
    res.redirect(...);
  }
}

What will happen in this case, is that first the browser will get redirected to the url in req.query.return, then express will respond to the new request with a match on index.php. This is ok, but if the infrastructure is complicated, it will take some time for client browser to issue a new request (might even be 0.5-1 seconds if the person accessing the website is technically far from the server).

Any way I could take the req.query.return and have something like app.processNewUrl(req.query.return)?



via Alex

No comments:

Post a Comment