I'd like to rewrite my app using pylons but I've noticed the problem at
very beginning.
I offer some stuff for users and use subdomains to do so. So
www.mysite.com is main page of the site, and user.mysite.com is a user
specyfic page (eg. blog or something). And my questions is how to map
this using routes?
One possible solution is to rewrite URLs at web server level from
xxx.mysite.com/ to mysite.com/xxx/ and map it with routes. It's ok, but
I've got 2 questions.
First, how can I write a middleware or something to make this rewrite
at pylons level?
Second, what to do not to break helpers like url_for() and link_to()? I
could just write a new version of url_for and substitute it, but I
don't know how to get into python mechanizm...
Is there such system in pylons like in ruby on rails so I can just
write plugin which will do URL rewrite before mapping and which will
add something like decorator to url_for?
I can't find any documentation on how to this... Thanks for any help.
You can now use an additional map option in yourproj/lib/routing.py,
map.sub_domains = True
And either require a sub domain to be present:
map.connect('', controller='user', action='home',
conditions=dict(sub_domains=True))
Or require a range of specific sub-domains:
map.connect('', controller='user', action='home',
conditions=dict(sub_domains=['fred','george']))
If you have multiple sub-domains that are equivilant to your hostname
(www.host.com == host.com), you can ignore those with:
map.sub_domains_ignore =['www']
url_for will now also handle the sub_domain keyword, ie:
url_for(action='list', sub_domain='george')
This will generate a URL with the sub-domain of 'george' based off the
current domain information. To determine the current domain name, a
regexp of: [^\.\/]+?\.[^\.\/]+ is used. Which will map
anything.anything, if you have a longer base (ie, domain.com.pl), you
can override the match:
map.domain_match = 'new_match_here'
Let me know how it works out for you.
HTH,
Ben
def view(self, id, sub_domain):
if sub_domain:
pass # do something with it
Cheers,
Ben