On Mar 14, 2012, at 6:49 AM, Anthony wrote: > I'm not sure if it will work, but you might try something like this in > routes.py: > > routes_in = ( > (r'.*?://(?P<sub>[^.]*).*?/app/web/site/(?P<any>.*)', > r'/app/web/site/\g<sub>/\g<any>') > ) > > Note, that uses the pattern-based rewrite system, which cannot be mixed with > the parameter-based rewrite system, so make sure your routes.py does not > contain a "routers" dictionary (which will take precedence over any > routes_in/routes_out). > > I suppose you'll also need a routes_out. It probably just needs to remove the > subdomain arg from the URL: > > routes_out = ( > (r'/app/web/site/(?P<sub>.*?)/(?P<any>.*)', r'/app/web/site/\g<any>') > ) > > Anthony
Another approach would be to use the parametric router, setting the defaults to app/web/site, and in the model extract the subdomain from request.env and prepend it to request.args. Notice that the routes_out editing (or the equivalent in the parametric case) is tricky, because it depends on the domain that the browser used to access the site. If the request came in as domain.com/.../DEMO/..., you can't remove DEMO in routes.out. OTOH, if the request was made to DEMO.domain.com/..., then you must remove DEMO from the outgoing URL. If it's there in the first place. The parametric router has some logic for this when it does subdomain routing to an app or app/controller, but generally speaking it seems to me that the best policy is to require incoming requests to be of one form or the other, and not to mix them. Otherwise you're bound to get cross-subdomain confusion. > > On Monday, March 12, 2012 3:42:49 PM UTC-4, Carlos wrote: > Hi, > > My previous related post: > https://groups.google.com/d/topic/web2py/TxACULvgxik/discussion > > Following is my url path structure to access websites for multiple > Organizations (ORG) > > http:// domain.com / app / web / site / ORG / args ? vars > > I can successfully access the website for DEMO ORG as: > > http:// domain.com / app / web / site / DEMO / args ? vars > > And I am using the following BASE routes dict: > > default_application = 'app' > default_controller = 'web' > default_function = 'site' > > So I can now use short urls: > > http:// domain.com / site / DEMO / args ? vars > > But now I require to access it via subdomain (removing 'site' function and > ORG first arg, but being able to keep using args and vars): > > http:// DEMO.domain.com / args ? vars > > Internally rewriting to: http:// domain.com / app / web / site / DEMO / args > ? vars > > Is there any way I can accomplish this with routes?. > > Thanks, > > Carlos >