title: How to route a single web2py application with the shortest possible URL without losing the admin application
body: <p>I have a web2py website that has two applications: the standard admin application and a custom 'myapp' application.  For the sake of discussion we will say that the website lives at 'sub.projdomain.com'. I have been trying for hours to wrap my head around routes and python regular expressions, but I cannot seem to nail the functionality I desire.  I am attempting to replicate the following behavior:</p>
  
  <pre><code>URL in address bar               Effective URL
  ------------------               -------------
  sub.projdomain.com               sub.projdomain.com/myapp/default/index
  sub.projdomain.com/              sub.projdomain.com/myapp/default/index
  sub.projdomain.com/foo           sub.projdomain.com/myapp/foo/index
  sub.projdomain.com/foo?p=1       sub.projdomain.com/myapp/foo/index?p=1
  sub.projdomain.com/foo/?p=2      sub.projdomain.com/myapp/foo/index?p=2
  sub.projdomain.com/foo/bar?p=3   sub.projdomain.com/myapp/foo/bar?p=3
  sub.projdomain.com/foo/bar/?p=4  sub.projdomain.com/myapp/foo/bar?p=4
  sub.projdomain.com/a             sub.projdomain.com/admin/default/site
  </code></pre>
  
  <p>I always seem to have the problem where I call URL('login') or URL('/login') from the page "sub.projdomain.com/foo/bar/" and get a bad URL of the form "sub.projdomain.com/foo/login/" or something similar.  Currently I am setting the 'routes_in' and 'routes_out' tuples because I couldn't get it working with 'routers'.  I feel like I am overlooking what should be a very simple set of routes.  Am I overthinking the problem?</p>
  
  <p>---- UPDATE ----</p>
  
  <p>Alright, I think I managed to figure out a set of routes to get the behavior I want, but I would really like to know if this is the correct way to accomplish it.</p>
  
  <pre><code>routes_in = (
      #Map the default index to '/'
      ('/', '/myapp/default/index'),
      #Allow the admin application to be accessed
      ('/a', '/admin/default/index'),
      ('/a/$anything', '/admin/$anything'),
      #Re-wire actions as controllers unless the controller is also specified
      ('/$controller', '/myapp/$controller/index'),
      ('/$controller/', '/myapp/$controller/index'),
      ('/$controller/$action', '/myapp/$controller/$action'),
      #Map static access to our app
      ('/static/$anything', '/myapp/static/$anything'),
  )
  routes_out = [(x, y) for (y, x) in routes_in]
  </code></pre>
  
  <p>This setup requires that I carefully construct the parameters that I pass to URL(..).  I would like it to be easier to predict what URL(..) produces, but I doubt it gets any simpler than this... any help is appreciated!</p>