Re: [web2py] Subdomain based on blog users in routes.py
On Oct 5, 2011, at 7:36 AM, Farsheed Ashouri wrote: ya, It works, but it's not was i expected. for example my own blog rodmena.ourway.ir now redirects to it's correct path, but i wanted to stay at sub domain level while surfing. my code is simple: # Blogs subdomain redirection === host_parts = request.env.http_host.split('.') if len(host_parts) == 3: subdomain = host_parts[0] main_domain = '%s.%s' % (host_parts[1], host_parts[2]) red_link= '%s://%s/pages/blog?u=%s' % (request.env.wsgi_url_scheme, main_domain, subdomain) redirect(red_link) # Btw, thx all for their answer, but i still need to solve it in routes. Try putting this in db.py (or your first model file, whatever it is). (This is strictly experimental, and I'm assuming that you have all your model files in the top level of the model directors.) host_parts = request.env.http_host.split('.') if len(host_parts) == 3: request.vars['u'] = host_parts[0] # subdomain request.controller = 'pages' request.function = 'blog' response.view = '%s/%s.%s' % (request.controller, request.function, request.extension)
Re: [web2py] Subdomain based on blog users in routes.py
Well it worked!! but with many problems in Ajax loading! Thank you, but any improvements??
Re: [web2py] Subdomain based on blog users in routes.py
On Oct 5, 2011, at 8:03 AM, Farsheed Ashouri wrote: Well it worked!! but with many problems in Ajax loading! Thank you, but any improvements?? You might want to look at request.controller (and .function and .extension) to detect Ajax requests and do something else with them (depending on what the Ajax problems are). Otherwise all your Ajax requests coming from the subdomain will be sent to pages/blog, which is probably wrong.
Re: [web2py] Subdomain based on blog users in routes.py
ya, I am trying to solve it. Let's see what'll come up with this night! :)) Thank you Jonathan! On Wed, Oct 5, 2011 at 6:38 PM, Jonathan Lundell jlund...@pobox.com wrote: On Oct 5, 2011, at 8:03 AM, Farsheed Ashouri wrote: Well it worked!! but with many problems in Ajax loading! Thank you, but any improvements?? You might want to look at request.controller (and .function and .extension) to detect Ajax requests and do something else with them (depending on what the Ajax problems are). Otherwise all your Ajax requests coming from the subdomain will be sent to pages/blog, which is probably wrong. -- Sincerely, Farsheed Ashouri, ourway.ir Tel: +98 9388801504
Re: [web2py] Subdomain based on blog users in routes.py
I'm not sure about reading URLs (incoming or outgoing), but for re-writing them, there is an example in http://web2py.com/book/default/chapter/04#Pattern-Based-System showing a re-write involving the query string: '/test/default/index?vars=\gany' Presumably if any could be a match of the subdomain, this would work. Anthony On Saturday, October 1, 2011 6:23:10 PM UTC-4, Jonathan Lundell wrote: On Oct 1, 2011, at 3:13 PM, Jonathan Lundell wrote: On Oct 1, 2011, at 2:13 PM, Farsheed Ashouri wrote: I think i have no problem with DNS. cause i put a * value in subdomain setting of DNS and now i have access to any sub-domain i want. So you say there is no way to solve this in routes.py? With the regex mode, perhaps. On second thought, I *think* that the regex router doesn't give you access to the query string. So you might have to make the user part of the arg string (part of the URL path) in order for the router to work for you.
Re: [web2py] Subdomain based on blog users in routes.py
On Oct 2, 2011, at 7:23 AM, Anthony wrote: I'm not sure about reading URLs (incoming or outgoing), but for re-writing them, there is an example in http://web2py.com/book/default/chapter/04#Pattern-Based-System showing a re-write involving the query string: '/test/default/index?vars=\gany' Presumably if any could be a match of the subdomain, this would work. Yes no. I was confused, and my answer was confusing. As I read the code, routes_in has no access to the incoming query string (which is fine here), but any query string that it emits is appended to the incoming query string, if any. That should suffice. routes_out (used by URL()), also has no access to the outgoing query string. That's probably OK in this case, since we don't want to actually put the host in the URL. This implies that any request from a particular user must come in on that user's subdomain, or if not, there'd need to be a redirection to get it there. I think. Anthony On Saturday, October 1, 2011 6:23:10 PM UTC-4, Jonathan Lundell wrote: On Oct 1, 2011, at 3:13 PM, Jonathan Lundell wrote: On Oct 1, 2011, at 2:13 PM, Farsheed Ashouri wrote: I think i have no problem with DNS. cause i put a * value in subdomain setting of DNS and now i have access to any sub-domain i want. So you say there is no way to solve this in routes.py? With the regex mode, perhaps. On second thought, I *think* that the regex router doesn't give you access to the query string. So you might have to make the user part of the arg string (part of the URL path) in order for the router to work for you.
Re: [web2py] Subdomain based on blog users in routes.py
On Sep 28, 2011, at 8:13 PM, Farsheed Ashouri wrote: Hi everyone, I have a blog system and I need a pages like: mysite.com/myappName/pages/blog?u=user1 map to something like this: user1.mysite.com I've read many posts here, the book and other resources i idea how this regexpr thing works. Could you please show meexactly how this example works in routes.py? I am searching for a day in forums and I am really tired of searching. (i feel like a fool!! :(( ) Really thank you in advanced. There's no way for the parametric router to do this. The pattern-based router might be able to. How do you plan to handle DNS for the subdomains?
Re: [web2py] Subdomain based on blog users in routes.py
I think i have no problem with DNS. cause i put a * value in subdomain setting of DNS and now i have access to any sub-domain i want. So you say there is no way to solve this in routes.py?
Re: [web2py] Subdomain based on blog users in routes.py
Until you figure out how to do it in routes.py, how about: if request.vars.u: redirect('%s.mysite.com' % request.vars.u)
Re: [web2py] Subdomain based on blog users in routes.py
On Oct 1, 2011, at 2:13 PM, Farsheed Ashouri wrote: I think i have no problem with DNS. cause i put a * value in subdomain setting of DNS and now i have access to any sub-domain i want. So you say there is no way to solve this in routes.py? With the regex mode, perhaps.
Re: [web2py] Subdomain based on blog users in routes.py
On Oct 1, 2011, at 3:13 PM, Jonathan Lundell wrote: On Oct 1, 2011, at 2:13 PM, Farsheed Ashouri wrote: I think i have no problem with DNS. cause i put a * value in subdomain setting of DNS and now i have access to any sub-domain i want. So you say there is no way to solve this in routes.py? With the regex mode, perhaps. On second thought, I *think* that the regex router doesn't give you access to the query string. So you might have to make the user part of the arg string (part of the URL path) in order for the router to work for you.
[web2py] Subdomain based on blog users in routes.py
Hi everyone, I have a blog system and I need a pages like: mysite.com/myappName/pages/blog?u=user1 map to something like this: user1.mysite.com I've read many posts here, the book and other resources i idea how this regexpr thing works. Could you please show me *exactly* how this example works in routes.py? I am searching for a day in forums and I am really tired of searching. (i feel like a fool!! :(( ) Really thank you in advanced.