论坛首页 编程语言技术论坛

子域名分发

浏览 3665 次
锁定老帖子 主题:子域名分发
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2007-02-13  
网上有个现成的RIALS插件,在ROUTES里面可以置:subdomain不过这样好像无法结合数据库

JAVAEYE搞的好神秘,吞吞吐吐的不愿说,不如我们今天就讨论下吧.

比如说这样一个应用,我有一个论坛,我给每个用户都要分配一个BLOG,每个BLOG都有一个子域名.

首先我先在APACHE里面设置泛解析
<vhost *:80>
  //some settings....
</vhost


然后我到application.rb里面设置一个
before_filter :subdomain_dispatch


写一个protected方法

def subdomain_dispatch
    subdomain=request.subdomains
    if (subdomain != "www"&&controller_name!="blogs")
	redirect_to blog_path
    end
end


简单的测试了一下,这样好像大概就可以跑起来了, 砸我吧.
   发表时间:2007-03-11  
Have you ever wanted to write Rails routes using a URL's subdomain? What about routing based on whether a request was HTTP vs HTTPS? Well, now you can. Recently Dan Webb released his "Request Routing Plugin":http://svn.vivabit.net/external/rubylibs/requestrouting/README for public use. This plugin lets you create routing rules that use a whole slew of new properties: domain, subdomain, method, port, remoteip, contenttype, accepts, requesturi, and protocol.

You can obtain the plugin from Dan's subversion repository:

ruby script/plugin install \
http://svn.danwebb.net/external/rails/plugins/request_routing/
0 请登录后投票
论坛首页 编程语言技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics