基于Web2Py的routes.py中的函数定义子域 [英] defining sub-domain based on a function in routes.py of Web2Py

查看:95
本文介绍了基于Web2Py的routes.py中的函数定义子域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有此页面:

http://mysite.org/myapp/pages/blog?name=user9

我需要这个:

user9.mysite.org

我应该在routes.py中写些什么?

What should i write in my routes.py?

推荐答案

好,所以我认为这有点误解了.您需要从web2py应用程序提供user9.mysite.org.一种方法是,如果将网站托管在mysite.org上,则是将所有请求(无论子域如何)都传递到web2py应用程序(您需要DNS提供商使用* .mysite.org这样的A记录: http://kb.mediatemple.net/questions/791/DNS+Explained#/A_Record )

Ok, so i think misinterpreted this a little. You need user9.mysite.org to be served from the web2py app. One way, if you have your site hosted at mysite.org, is to pass all requests (regardless of subdomain) to the web2py application (you'll need an A record like *.mysite.org with your DNS provider: http://kb.mediatemple.net/questions/791/DNS+Explained#/A_Record )

然后,您可以使用路线

类似的东西:

routes_in = (
  ('http://(?P<user>.*).mysite.org/(?P<any>.*)',
  '/app/pages/blog/\g<any>?name=\g<user>'),
) 

< any>将保存您可能需要的所有参数.这应该将来自user9.mysite.org的请求映射到mysite.org/app/pages/blog/<args>?name=user9

The <any> will save any args you may need. This should map a request from user9.mysite.org to mysite.org/app/pages/blog/<args>?name=user9

您可能需要稍作尝试才能使其正常工作.关键是要确保将对mysite.org的任何子域的请求直接发送给应用程序.这意味着,如果您访问www.mysite.org,mysite.org,somerandomfakesubdomain.mysite.org,则您将始终与mysite.org到达同一地点.您可能需要在Blog函数中添加一些逻辑,以确保子域字符串(例如user9)代表有效用户.

You might have to play with it a little to get it working. The key is to make sure that a request to any subdomain of mysite.org be given directly to the app. Meaning if you go to www.mysite.org, mysite.org, somerandomfakesubdomain.mysite.org, you'll always get to the same place as mysite.org. You'll probably want to put some logic in your blog function to ensure that the subdomain string (e.g. user9) represents a valid user.

这篇关于基于Web2Py的routes.py中的函数定义子域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆