Rails 301 Redirection
Using 301 redirect in Rails
class RedirectController < ApplicationController def index redirect_to :root, :status => :moved_permanently endend
I didn't try this, but something like this should work:
class ApplicationController < ActionController::Base before_filter :correct_domain! private def correct_domain! unless request.host == 'www.mysite.com' redirect_to root_url, :status => 301 # or explicitly 'http://www.mysite.com/' end endend
But I'm not sure if the trailing slash is present in the host attribute...