routes for subdomains

246 views
Skip to first unread message

Carlos

unread,
Jan 10, 2012, 10:14:35 AM1/10/12
to web...@googlegroups.com
Hi,

My environment: latest web2py, ubuntu, postgresql, nginx, uwsgi.

I need to handle multiple subdomains:

   http:// sub.domain.com / args ? vars

All of them must internally point to the following url structure:

   http:// www.domain.com / app / controller / function / sub / args ? vars

The whole url path (domain, app, controller, function) will be exactly the same in all subdomain cases, but each subdomain must be passed as the first arg (plus all the other args and vars), and it must handle incoming and outgoing urls.

Examples:

   from:  http:// test.domain.com /
   to:  http:// www.domain.com / app / controller / function / test

   from:  http:// demo.domain.com / arg1 / arg2 ? var1=1 & var2=2
   to:  http:// www.domain.com / app / controller / function / demo / arg1 / arg2 ? var1=1 & var2=2

Should this be somehow solved with web2py's parameter or pattern based routes?.

Your help is greatly appreciated, thanks!

   Carlos

Jonathan Lundell

unread,
Jan 10, 2012, 10:34:44 AM1/10/12
to web...@googlegroups.com
The parametric router won't do this for you directly. You could, though, use the parametric router and put something like this at the beginning of db.py: extract the subdomain from request.env.get('HTTP_HOST') and insert it as element 0 of request.args.

web2py's outgoing URLs don't ordinarily include the domain, unless you explicitly pass it (or a scheme) to URL() as an argument. 

WAYRTTD?

Massimo Di Pierro

unread,
Jan 10, 2012, 12:27:15 PM1/10/12
to web2py-users
The parametric router cannot do this but the regular web2py routing
does.

Here is an example

routes_in = (
('.*:https?://yourdomain.com:(GET|POST) /$anything','/app/
$anything'),
)

the .* means the route applies to all client IPs. https? means you
take both http and https. (GET|POST) means the route applies to both
GET and POST. The final part does the mapping.

On Jan 10, 9:14 am, Carlos <carlosgali...@gmail.com> wrote:
> Hi,
>
> My environment: latest web2py, ubuntu, postgresql, nginx, uwsgi.
>
> I need to handle multiple subdomains:
>
>    http:// sub.domain.com / *args ? vars*
>
> All of them must internally point to the following url structure:
>
>    http://www.domain.com/ app / controller / function / sub / *args ? vars
> *
>
> The whole url path (domain, app, controller, function) will be exactly the
> same in all subdomain cases, but each subdomain must be passed as the first
> arg (plus all the other args and vars), and it must handle incoming and
> outgoing urls.
>
> Examples:
>
>    from:  http:// test.domain.com /
>    to:  http://www.domain.com/ app / controller / function / test
>
>    from:  http:// demo.domain.com / *arg1 / arg2 ? var1=1 & var2=2*
>    to:  http://www.domain.com/ app / controller / function / demo / *arg1
> / arg2 ? var1=1 & var2=2*

Carlos

unread,
Jan 12, 2012, 1:23:46 PM1/12/12
to web...@googlegroups.com
Thanks Jonathan and Massimo for your input !

Larry Wapnitsky

unread,
Mar 16, 2012, 4:33:15 PM3/16/12
to web...@googlegroups.com
Massimo-

I'm still a little unclear on this.  I have a setup where web2py is a subfolder of  my public_html folder.  I have two domains, A and B.  I'd like for the following

sub1.ADomain.com to go to public_html/web2py/appA1/default/index
sub2.ADomain.com             public_html/web2py/appA2/default/index
sub3.BDomain.org               public_html/web2py/appB3/default/index

I tried playing with the advice listed above and only wound up with 404s.

TIA
Reply all
Reply to author
Forward
0 new messages