title: How do I redirect relative to the express application root?
body: <p>I want to make my app so that it can be mounted at some location other than <code>/</code>. When I read the docs for express-4.x’s <a href="http://expressjs.com/en/api.html#res.redirect" rel="nofollow noreferrer"><code>res.redirect()</code></a>, it says I have three options:</p>
  
  <ol>
  <li>Absolute URI (<code>http://example.org/path/nested</code>)</li>
  <li>Host-relative (<code>/path/nested</code>)</li>
  <li>URI-relative (<code>nested</code>)</li>
  </ol>
  
  <p>I don’t see any option for application-relative redirects.</p>
  
  <p>Example of how an app might  be mounted within another:</p>
  
  <pre><code>'use strict';
  
  const express = require('express');
  
  const app = express();
  module.exports = app;
  
  const subApp = express();
  app.use('/subApp', subApp);
  
  subApp.get('/blah/*', (req, res) =&gt; {
      if (/dee$/.test(req.url)) {
          res.end('end');
      } else {
          res.redirect('dee');
      }
  });
  </code></pre>
  
  <p>How do I redirect to the root URI of <code>subApp</code> without requiring the code in <code>subApp</code> to know its mountpoint? Maybe there is a way I can construct it from information in <code>req</code>?</p>