我认为这应该很容易,但是我不熟悉它的完成方式...
I think this should be fairly easy but I'm not familiar with how it's done...
您如何编写一个before过滤器来检查是否当前请求是针对某些子域的,如果是这样,将其重定向到相同的URL,但在不同的子域上?
How do you write a before filter that would check if the current request is for certain subdomains, and if so redirect it to the same url but on a different subdomain?
即: blog.myapp / posts / 1 很好,但 blog.myapp/products/123 重定向到 www.myapp/产品/ 123 。
Ie: blog.myapp/posts/1 is fine but blog.myapp/products/123 redirects to www.myapp/products/123.
我在想类似...
class ApplicationController < ActionController::Base before_filter :ensure_domain protected def ensure_domain if request.subdomain == 'blog' && controller_name != 'posts' redirect_to # the same url but at the 'www' subdomain... end end end如何编写该重定向?
推荐答案ActionController :: Redirecting#redirect_to 允许您传递绝对URL,因此最简单的方法是要做的就是通过以下方式传递它:
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')更多推荐
Rails:重定向到当前路径,但不同的子域
发布评论