Skip to content

Instantly share code, notes, and snippets.

@abriening
Created October 15, 2012 18:13
Show Gist options
  • Save abriening/3894103 to your computer and use it in GitHub Desktop.
Save abriening/3894103 to your computer and use it in GitHub Desktop.
require 'rack/rewrite'
config.middleware.use Rack::Rewrite do
has_www = proc{|env| env['SERVER_NAME'] =~ /^www\./i }
replace_www = proc{|path, env| Rack::Request.new(env).url.sub(/www\./i, '') }
r301 /.*/, replace_www, :if => has_www
end
gem 'rack-rewrite'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment