User subdomains

5 views
Skip to first unread message

krypton

unread,
Dec 6, 2006, 4:02:13 PM12/6/06
to web.py
Hello

Hi I want to do user subdomains such as

webpy.infogami.com

or krypton.slide.com

how do we achieve this in webpy + lighty

thanks

Krypton

Tom Berger

unread,
Dec 7, 2006, 5:56:45 PM12/7/06
to we...@googlegroups.com
On 12/6/06, krypton <krypton...@yahoo.com> wrote:
Hi I want to do user subdomains

You can rewrite the url so that subdomain.domain.org is transformed to domain.org/subdomain (I have no idea how you do that in lighttpd, but it should be possible), then create urls that use this as a parameter, for example:

urls = (
  '/([a-z0-9\-]*)/home', 'home',
  '/([a-z0-9\-]*)/profile', 'profile'
)

class home:
  def GET(self, user):
    render.home(user)

class profile:
  def GET(self, user):
    render.profile(user)


Anand

unread,
Dec 7, 2006, 8:45:16 PM12/7/06
to we...@googlegroups.com

> Hi I want to do user subdomains such as
>
> webpy.infogami.com
>
> or krypton.slide.com
>
> how do we achieve this in webpy + lighty


This is the lighttpd configuration you need.

$HTTP["host"] =~ "^.*slide.com$" {
server.document-root = "/path/to/code/"
fastcgi.server = ( "/run.py" =>
(( "socket" => "/tmp/slide.socket",
"bin-path" => "/path/to/code/run.py",
"max-procs" => 1
))
)

url.rewrite-once =(
"^/favicon.ico$" => "/static/favicon.ico",
"^/static/(.*)$" => "/static/$1",
"^/(.*)$" => "/run.py/$1",
)
}

and in web.py code, you can get the hostname by looking at web.ctx.host.

blaf

unread,
Dec 7, 2006, 8:53:31 PM12/7/06
to web.py
You first need to add a wildcard dns entry to respond to any subdomains
and point it to your lighty server. After you need something like
$HTTP["host"] =~ "\.domain\.com" in your lighty vhost config.

John

unread,
Dec 7, 2006, 9:15:55 PM12/7/06
to we...@googlegroups.com
now all the hits to
my.slide.com
anand.slide.com
web.slide.com will all goto '/'
and / is mapped to index in urls

how do i map anand.slide.com to profile/anand

and web.slide.com to profile/web

thanks a lot

Anand <anand...@gmail.com> wrote:

Cheap Talk? Check out Yahoo! Messenger's low PC-to-Phone call rates.

Anand

unread,
Dec 7, 2006, 10:21:45 PM12/7/06
to we...@googlegroups.com

On 08-Dec-06, at 7:45 AM, John wrote:

now all the hits to

my.slide.com

anand.slide.com

web.slide.com will all goto '/'

and / is mapped to index in urls


how do i map anand.slide.com to profile/anand


and web.slide.com to profile/web


Why do you want to do it like that? what about other urls like anand.slide.com/something?
I think it is goof to use web.ctx.host to idenify what action to be taken?

One possible hack i can think of is this. 
may be i will be able to suggest a better solution, if you can discuss some more details of the problem.

# all your code goes here

def handler():
   # changing the web.ctx.path to redirect request to profiles/name
   match = re.match(r'(.*).slide.com', web.ctx.host)
   if match:
       web.ctx.path = "/profile/%s/%s" % (match.group(1), web.ctx.path)
    
   return web.request.handle(urls, globals())

if __name__ == "__main__":
    web.run(handler, globals())

It redirects all requests to name.slide.com/abcd to /profiles/name/abcd
caution: i haven't tested this code.

Reply all
Reply to author
Forward
0 new messages