Skip to content

Instantly share code, notes, and snippets.

@wjessop
Created April 15, 2010 11:01
Show Gist options
  • Save wjessop/366975 to your computer and use it in GitHub Desktop.
Save wjessop/366975 to your computer and use it in GitHub Desktop.
class Downcase
def initialize(app)
@app = app
end
def call(env)
# execute the request using our Rails app
status, headers, body = @app.call(env)
if status == 404 and url = downcased_url(env['REQUEST_URI'])
# "Moved permanently" to new url
[301, {"Location" => url}, 'Redirecting']
else
# return the result from rails
[status, headers, body]
end
end
def downcased_url(path)
new_path = path.downcase
if new_path == path
# path's are the same
return false
else
return new_path
end
end
end
Rails::Initializer.run do |config|
# <snip>
config.middleware.use 'Downcase'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment