When you use parameter router system, you have the possibility to set a dictionary mapping each domain with an app and then set exclusive_domain=True, this way each app is accessible only through its assigned domain.
But how to do that when using pattern routes?
I'm serving several domains; two web2py apps for each domain.
How do I configure routes to allow access to only those two apps per domain?
Each domain works with two apps:
- recipes.com
- applications/recipes/
- applications/recipes_panel/
- traveler.com
- applications/traveler/
- applications/traveler_panel/
In order to get this to work, first we need routes.py in the main folder of web2py:
routes_app = [
(r'.*?://recipes.com:\w* /$anything', r'recipes'),
(r'.*?://traveler.com:\w* /$anything', r'traveler')
]
Then, we need applications/recipes/routes.py:
routes_in = [
('/', '/recipes/default/index'),
('/robots.txt', '/recipes/static/robots.txt'),
('/favicon.png', '/recipes/static/custom/favicon.png'),
('/download$anything', '/recipes/default/download$anything'),
('/panel/download$anything', '/recipes_panel/default/download$anything'),
('/static$anything', '/recipes/static$anything'),
('/panel/static$anything', '/recipes_panel/static$anything'),
('/panel', '/recipes_panel/default/index'),
('/panel$anything', '/recipes_panel$anything'),
]
routes_out = [(x, y) for (y, x) in routes_in]
And then applications/traveler/routes.py
routes_in = [
('/', '/traveler/default/index'),
('/robots.txt', '/traveler/static/robots.txt'),
('/favicon.png', '/traveler/static/custom/favicon.png'),
('/download$anything', '/traveler/default/download$anything'),
('/panel/download$anything', '/traveler_panel/default/download$anything'),
('/static$anything', '/traveler/static$anything'),
('/panel/static$anything', '/traveler_panel/static$anything'),
('/panel', '/traveler_panel/default/index'),
('/panel$anything', '/traveler_panel$anything'),
]
routes_out = [(x, y) for (y, x) in routes_in]
However, if go to traveler.com/recipes/default/index I can still access "recipes" app, and I don't want that. Is it possible to restrict the access using pattern based routes?