Skip to content

Instantly share code, notes, and snippets.

@nowaterlili
Created February 11, 2012 06:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nowaterlili/1797064 to your computer and use it in GitHub Desktop.
Save nowaterlili/1797064 to your computer and use it in GitHub Desktop.
config.ru for redirecting www to non www
require "rack-rewrite"
ENV['RACK_ENV'] ||= 'development'
if ENV['RACK_ENV'] == 'development'
ENV['SITE_URL'] = 'yoursite.local:3000'
else
ENV['SITE_URL'] = 'yoursite.com'
end
use Rack::Rewrite do
r301 %r{.*}, "http://#{ENV['SITE_URL']}$&", :if => Proc.new { |rack_env|
rack_env['SERVER_NAME'].start_with?('www')}
r301 %r{^(.+)/$}, '$1'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment