2 domains served by the same web2py

99 views
Skip to first unread message

António Ramos

unread,
Oct 24, 2013, 5:12:07 AM10/24/13
to web...@googlegroups.com
hello, i need another domain served by my web2py  in windows 7

I have www.site1.pt served my web2py server , no i need another 
www.site2.pt served also by my web2py server 

I have my firewall setup and my dns to point to my web2py but how do i setup web2py  to serve 2 domains?

Thank you

Loïc

unread,
Oct 24, 2013, 6:46:22 AM10/24/13
to web...@googlegroups.com
Did you try using routes.py?
Something like

# -*- coding: utf-8 -*-

routes_app
= (
   
(r'.*?:https?://www.site1.pt:\w* /$anything', r'site1'),
   
(r'.*?:https?://www.site2.pt:\w* /$anything', r'site2')
)

António Ramos

unread,
Oct 24, 2013, 7:06:46 AM10/24/13
to web...@googlegroups.com
I have now these apps



how do i write my routes.py for these apps?



2013/10/24 Loïc <loic....@gmail.com>


Loïc

unread,
Oct 24, 2013, 5:19:05 PM10/24/13
to web...@googlegroups.com
Considering my previous post, and the routes documentation :http://www.web2py.com/books/default/chapter/29/04/the-core?search=routes#Routes-on-error

Did you try to set up you routes.py file? Do you have a specific problems / error messages? Can you show us some code?

Paolo Valleri

unread,
Oct 25, 2013, 2:20:25 AM10/25/13
to web...@googlegroups.com
I've this setup on a server:
routers = dict(
    BASE  = dict(
        default_application='vtraffic',
        default_controller='default',
        root_static = ['favicon.ico', 'robots.txt', 'google51a05a100c482cad.html', 'sitemap.xml'],
domains = {'traffic.integreen-life.bz.it':'vtraffic',
),
    vtraffic = dict(languages=['en', 'it', 'de']),
    parkbz = dict(languages=['en', 'it', 'de']),
)


hope it helps
Paolo

António Ramos

unread,
Oct 25, 2013, 5:09:23 AM10/25/13
to web...@googlegroups.com
I dont get it.


i tried this with no success
i created an empty routes.py file in my web2py folder 
then inside i wrote

# -*- coding: utf-8 -*-

routes_app = (
    (r'.*?:http?://www.cires.pt:\w* /$anything', r'welcome'),
    (r'.*?:http?://apps.cires.pt/empre:\w* /$anything', r'empre'),
    (r'.*?:http?://apps.cires.pt/erp:\w* /$anything', r'welcome')
)

the last tuple i wrote to test if http?://apps.cires.pt/erp would redirect to the welcome app. It did not!


I think this routes.py is being ignored.
Also i think i dont get it how to use routes.py

Thank you for your info


2013/10/25 Paolo Valleri <paolo....@gmail.com>

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Loïc Espern

unread,
Oct 25, 2013, 5:17:23 AM10/25/13
to web...@googlegroups.com
So, you have define your base "routes.py" on web2py folder.
Then, do you have set up an app-specific routes.py in your application folder?

For example, in welcome app you should have a routes.py file containing something like (just a stupid example from one of my apps) :

# -*- coding: utf-8 -*-
routes_in = (
  (r'/whatever', r'/welcome/default/whatever'),
  (r'/contact', r'/welcome/default/contact_form'),
  (r'/robots.txt', r'/welcome/static/robots.txt'),
)

routes_out = [(x, y) for (y, x) in routes_in]


2013/10/25 António Ramos <ramst...@gmail.com>
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/rzxeYXHalgI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.

António Ramos

unread,
Oct 25, 2013, 7:30:20 AM10/25/13
to web...@googlegroups.com
it works now
in my web2py folder i created this routes.py

routes_in = (
((r'.*http://www.cires.pt.* (?P<any>.*)', r'/welcome/default\g<any>')),
 ((r'.*http://apps.cires.pt/empre.* (?P<any>.*)', r'/empre/default\g<any>')),
 ((r'.*http://apps.cires.pt/ERP.* (?P<any>.*)', r'/ERP/default\g<any>')),
   ((r'.*http://apps.cires.pt/DO.* (?P<any>.*)', r'/DO/default\g<any>')),
  ((r'.*http://www.previnil.pt.* (?P<any>.*)', r'/previnil/default\g<any>')),


 )

IT works!



2013/10/25 Loïc Espern <loic....@gmail.com>

António Ramos

unread,
Oct 25, 2013, 7:48:00 AM10/25/13
to web...@googlegroups.com
oops

  ((r'.*http://www.previnil.pt.* (?P<any>.*)', r'/previnil/default\g<any>')),

is not working.
It defaults to /welcome/
why?


2013/10/25 António Ramos <ramst...@gmail.com>

Jonathan Lundell

unread,
Oct 25, 2013, 10:23:53 AM10/25/13
to web2py
On 25 Oct 2013, at 2:17 AM, Loïc Espern <loic....@gmail.com> wrote:

So, you have define your base "routes.py" on web2py folder.
Then, do you have set up an app-specific routes.py in your application folder?

No, you can do everything in the root routes.py.

Jonathan Lundell

unread,
Oct 25, 2013, 10:36:53 AM10/25/13
to web2py
On 25 Oct 2013, at 2:09 AM, António Ramos <ramst...@gmail.com> wrote:

I dont get it.


i tried this with no success
i created an empty routes.py file in my web2py folder 
then inside i wrote

# -*- coding: utf-8 -*-

routes_app = (
    (r'.*?:http?://www.cires.pt:\w* /$anything', r'welcome'),
    (r'.*?:http?://apps.cires.pt/empre:\w* /$anything', r'empre'),
    (r'.*?:http?://apps.cires.pt/erp:\w* /$anything', r'welcome')
)

the last tuple i wrote to test if http?://apps.cires.pt/erp would redirect to the welcome app. It did not!

Your re's aren't quite right, and you should be defining routes_in, not routes_app (routes_app is used only if you have separate, app-specific routes.py files).

This is closer, though untested:

routes_in = (
    (r'.*?:https?://www\.cires\.pt:.* /$anything', r'/welcome/$anything'),
    (r'.*?:https?://apps\.cires\.pt:.* /empre/$anything', r'/empre/$anything'),
    (r'.*?:https?://apps\.cires\.pt:.* /erp/$anything', r'/welcome/$anything')

António Ramos

unread,
Oct 25, 2013, 11:04:11 AM10/25/13
to web...@googlegroups.com
routes_in = (
    (r'.*?:https?://www\.cires\.pt:.* /$anything', r'/welcome/$anything'),
    (r'.*?:https?://www\.previnil\.pt:.* /$anything', r'/previnil/$anything'),
    (r'.*?:https?://apps\.cires\.pt:.* /empre/$anything', r'/empre/$anything'),
    (r'.*?:https?://apps\.cires\.pt:.* /erp/$anything', r'/erp/$anything')
)

the bold route does not route to previnil app but to welcome!!!

Why?




2013/10/25 Jonathan Lundell <jlun...@pobox.com>

Jonathan Lundell

unread,
Oct 25, 2013, 11:22:24 AM10/25/13
to web2py
On 25 Oct 2013, at 8:04 AM, António Ramos <ramst...@gmail.com> wrote:

routes_in = (
    (r'.*?:https?://www\.cires\.pt:.* /$anything', r'/welcome/$anything'),
    (r'.*?:https?://www\.previnil\.pt:.* /$anything', r'/previnil/$anything'),
    (r'.*?:https?://apps\.cires\.pt:.* /empre/$anything', r'/empre/$anything'),
    (r'.*?:https?://apps\.cires\.pt:.* /erp/$anything', r'/erp/$anything')
)

the bold route does not route to previnil app but to welcome!!!

Why?


Not sure. Can you get to previnil OK with routing off?

António Ramos

unread,
Oct 25, 2013, 11:29:45 AM10/25/13
to web...@googlegroups.com
yes
 with the bold line commented out i stil go to welcome when i write in my browser http://www.previnil.pt

is that because welcome is the default app? 



2013/10/25 Jonathan Lundell <jlun...@pobox.com>

--

Jonathan Lundell

unread,
Oct 25, 2013, 12:09:27 PM10/25/13
to web2py
On 25 Oct 2013, at 8:29 AM, António Ramos <ramst...@gmail.com> wrote:

yes
 with the bold line commented out i stil go to welcome when i write in my browser http://www.previnil.pt

is that because welcome is the default app? 

It is, yes, so not a great path to use for testing.

Keep in mind that you should be restarting web2py when you make a change to routes.py; in general it only reads the file on startup.

António Ramos

unread,
Oct 25, 2013, 12:18:40 PM10/25/13
to web...@googlegroups.com
yes i reload the routes on every change to routes.py

but how do i route to previnil app when i write http://www.previnil.pt ???

I have my 2 dns pointing to my web2py server (www.cires.pt and www.previnil.pt)

Jonathan Lundell

unread,
Oct 25, 2013, 12:27:39 PM10/25/13
to web2py
On 25 Oct 2013, at 9:18 AM, António Ramos <ramst...@gmail.com> wrote:

yes i reload the routes on every change to routes.py

but how do i route to previnil app when i write http://www.previnil.pt ???

I have my 2 dns pointing to my web2py server (www.cires.pt and www.previnil.pt)

I'm about to be offline for most of the day, so won't be responding later.

Make sure you can route to the previnil app *somehow* first.

Then you might want to turn on logging for routes; that might help to see what's going on. And look at web2py's view of the incoming URL to make sure it's what you think it is (display a dump of request.env, for example).

Martin Weissenboeck

unread,
Oct 26, 2013, 1:59:33 AM10/26/13
to web...@googlegroups.com
May be

(r'.*https?://www\.previnil\.pt.* /$anything', r'/previnil/$anything'),

could help. I have a similar line which works.

António Ramos

unread,
Oct 26, 2013, 3:59:13 PM10/26/13
to web...@googlegroups.com
Still goes to the wrong app
The route you provided goes to welcome app


2013/10/26 Martin Weissenboeck <mwei...@gmail.com>

António Ramos

unread,
Oct 26, 2013, 4:04:09 PM10/26/13
to web...@googlegroups.com
routes_in = (
    
    (r'.*  https?://www\.previnil\.pt.* /$anything', r'/previnil/$anything'),
    (r'.*?:https?://www\.cires\.pt:.* /$anything', r'/welcome/$anything'),
    (r'.*?:https?://apps\.cires\.pt:.* /empre/$anything', r'/empre/$anything'),
    (r'.*?:https?://apps\.cires\.pt:.* /erp/$anything', r'/erp/$anything')
)

the bold line redirects to welcome app

again, i ask why is this code not working?
i have web2py  2.0.9 on windows 7

Do i need more code in routes.py?



2013/10/26 António Ramos <ramst...@gmail.com>

António Ramos

unread,
Oct 26, 2013, 4:09:25 PM10/26/13
to web...@googlegroups.com
bad news
i think my routes.py is being fully ignored because i changed some of the above lines to route to diferent apps and web2py did not redirected to other apps

so the point is not the bold line. is the routes.py file.

why is my routes.py being ignored?
no error when i restart web2py 
how do i trace the logs os the routes.py


2013/10/26 António Ramos <ramst...@gmail.com>

pa...@cancamusa.net

unread,
Oct 26, 2013, 4:45:56 PM10/26/13
to web...@googlegroups.com
A simpler approach is to rewrite the default controller in the default app, using request.url to get the url and redirect accordingly. Probably not optimal.

Jonathan Lundell

unread,
Oct 26, 2013, 4:50:29 PM10/26/13
to web2py
On 26 Oct 2013, at 1:04 PM, António Ramos <ramst...@gmail.com> wrote:

routes_in = (
    
    (r'.*  https?://www\.previnil\.pt.* /$anything', r'/previnil/$anything'),
    (r'.*?:https?://www\.cires\.pt:.* /$anything', r'/welcome/$anything'),
    (r'.*?:https?://apps\.cires\.pt:.* /empre/$anything', r'/empre/$anything'),
    (r'.*?:https?://apps\.cires\.pt:.* /erp/$anything', r'/erp/$anything')
)

the bold line redirects to welcome app

Are you sure? I suspect that it would go to welcome without that line. 

That is, for some reason, that line isn't being activated. It's not quite right anyway; should be:

    (r'.*?:https?://www\.previnil\.pt:.* /$anything', r'/previnil/$anything'),

António Ramos

unread,
Oct 26, 2013, 4:54:04 PM10/26/13
to web...@googlegroups.com
i tried
(r'.*?:https?://www\.previnil\.pt:.* /$anything', r'/previnil/$anything'),
(r'.*  https?://www\.previnil\.pt.* /$anything', r'/previnil/$anything'),
none of them redirected

all other routes are not working also because i changed them to redirect to other app and it did not!
is as if routes.py didnd exist. However if i make a mistake in the code on purpose when i reload route i got a ticket.
So routes.py is being read but not working as expected.




2013/10/26 Jonathan Lundell <jlun...@pobox.com>

Jonathan Lundell

unread,
Oct 26, 2013, 5:05:31 PM10/26/13
to web2py
On 26 Oct 2013, at 1:54 PM, António Ramos <ramst...@gmail.com> wrote:

i tried
(r'.*?:https?://www\.previnil\.pt:.* /$anything', r'/previnil/$anything'),
(r'.*  https?://www\.previnil\.pt.* /$anything', r'/previnil/$anything'),
none of them redirected

all other routes are not working also because i changed them to redirect to other app and it did not!
is as if routes.py didnd exist. However if i make a mistake in the code on purpose when i reload route i got a ticket.
So routes.py is being read but not working as expected.


Turn on rewrite logging.

António Ramos

unread,
Oct 26, 2013, 5:40:26 PM10/26/13
to web...@googlegroups.com
sorry but dont know how to turn on rewrite  logging


2013/10/26 Jonathan Lundell <jlun...@pobox.com>

--

Jonathan Lundell

unread,
Oct 26, 2013, 5:59:41 PM10/26/13
to web2py
On 26 Oct 2013, at 2:40 PM, António Ramos <ramst...@gmail.com> wrote:

sorry but dont know how to turn on rewrite  logging


Copy the logging.conf example file to the web2py root as logging.conf.

The logger you want to enable is web2py.rewrite, and set the log parameter in routes.py to something higher that debug. logging='warning' should do the trick. I've been using rotatingFileHandler, which works well. The stock logging.conf example file looks about right to me, without further changes.

António Ramos

unread,
Oct 26, 2013, 7:04:49 PM10/26/13
to web...@googlegroups.com
i installed a clean install of web2py and a simple line in routes.py does not route

so i go with this in my welcome default controller.

    if request.env['http_host']=="www.previnil.pt":
        redirect(URL(a='previnil',c='default',f='index'))


So sad that a simple line produces so much waste of time.


Also routes could be visible in admin 




2013/10/26 Jonathan Lundell <jlun...@pobox.com>

--

António Ramos

unread,
Oct 26, 2013, 7:28:13 PM10/26/13
to web...@googlegroups.com
i find that 
this line 
 (r'.*?:https?://apps\.cires\.pt:.* /empre$anything', r'/empre/$anything'),
instead of this
 (r'.*?:https?://apps\.cires\.pt:.* /empre/$anything', r'/empre/$anything'),

redirects to another app
Problem solved for app  routing ( 

however 
as i have two base domains pointing to my web2py

as the default app is welcome (where i have my www.cires.pt project )
this line
 (r'.*?:https?://www\.previnil\.pt:.* /$anything', r'/previnil/$anything'),
or this
 (r'.*?:https?://www\.previnil\.pt:.* $anything', r'/previnil/$anything'),

do not redirect to previnil app

i´m missing something here.

I need to sleep







2013/10/27 António Ramos <ramst...@gmail.com>
Reply all
Reply to author
Forward
0 new messages