Skip to content

Instantly share code, notes, and snippets.

@bensie
Forked from trevorturk/no_www.rb
Created March 27, 2012 19:17
Show Gist options
  • Select an option

  • Save bensie/2219401 to your computer and use it in GitHub Desktop.

Select an option

Save bensie/2219401 to your computer and use it in GitHub Desktop.
no-www rack middleware
class NoWww
def initialize(app)
@app = app
end
def call(env)
request = Rack::Request.new(env)
if request.host.starts_with?("www.")
[301, {"Location" => request.url.sub(/www./, "")}, self]
else
@app.call(env)
end
end
def each(&block)
end
end
require "rack/ssl"
require "no_www"
config.middleware.insert_before ::Rack::SSL, ::NoWww
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment