Created
April 15, 2010 11:01
-
-
Save wjessop/366975 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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