title: Express 4 define a new route inside a app.use route
body: <p>I have a express nodejs app, and I'm, trying to use "dynamic routes" inside another route.</p>
  
  <p>I have:</p>
  
  <pre><code>....
  app.use('/test/:id',
     function(req,res,next) {         
       app.use('/foo', static(path.join(__dirname, 'photos/'+req.params.id)));
       res.redirect('/foo/img1.jpg');
     }
  );
  </code></pre>
  
  <p>The res.redirect return "Not found" even if the file is present in the directory.</p>
  
  <p>I need this to serve static image photo file from a directory with sub-dir of album of photos, in a dynamic way, so I can upload new sub-dir without rewriting the routes in express.</p>
  
  <p>By the way, I'm using <a href="https://github.com/timmydoza/express-photo-gallery" rel="nofollow noreferrer">https://github.com/timmydoza/express-photo-gallery</a> and I'm trying to modify it to my needs.</p>
  
  <p>Thank you</p>
  
  <p><strong>UPDATED</strong>:</p>
  
  <p>I forget that if I extract the <code>app.use('/foo'....</code> outside the <code>app.use('/test/:id'...</code> the image is found.</p>