Rails: redirect to current path but different subdomain

后端 未结 3 1415
攒了一身酷
攒了一身酷 2021-01-01 19:44

I think this should be fairly easy but I\'m not familiar with how it\'s done...

How do you write a before filter that would check if the current request is for certa

相关标签:
3条回答
  • 2021-01-01 20:36

    A simple choice to redirect from subdomain to subdomain would be the following

    redirect_to subdomain: 'www', :controller => 'www', :action => "index"
    

    This would be called on a domain name for example foo.apple.com would then go to www.apple.com

    0 讨论(0)
  • 2021-01-01 20:46

    An even simpler option without the need to do a string sub or specify the controller or action would be to use

    redirect_to url_for(subdomain: 'www', only_path: false)
    
    0 讨论(0)
  • 2021-01-01 20:47

    ActionController::Redirecting#redirect_to allows you to pass an absolute URL, so the easiest thing to do would be to pass it one with something like:

    redirect_to request.url.sub('blog', 'www')
    
    0 讨论(0)
提交回复
热议问题