Hey folks,
I want to use dynamic subdomains as follows:
name1.domainapp.com
name2.domainapp.com
nameX.domainapp.com
When someone enters in these directions should be redirected to:
domainapp.com/name1
domainapp.com/name2
domainapp.com / NAMEX
I tried several examples I found and I end up doing this:
in __init__.py:
def pregen(request, elements, kw):
#kw['_app_url'] = 'http://www.muncomstores.com/' +
request.host.split('.')[0]
return elements, kw
def req_sub(info, request):
return request.host.split('.')[0] != 'www'
config.add_route('sub_only', '/{id:.*?}',
custom_predicates=(req_sub,),
#pregenerator=pregen
)
in views.py:
@view_config(route_name='sub_only')
def Subdomain(request):
# redirect the user to "http://sub.example.com", regardless of
whether
# request.host is "example.com" or "sub.example.com"
return HTTPFound(location='http://www.muncomstores.com/' +
request.host.split('.')[0])
Any suggestions to make it better?
Thanks
--
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/pylons-discuss/-/-SORrJRwtCsJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/pylons-discuss?hl=en.