Last active
December 29, 2015 01:39
-
-
Save rennex/7595143 to your computer and use it in GitHub Desktop.
If a request to my Sinatra app would return 404 just because of a trailing slash, redirect to the correct path.
This file contains 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
not_found do | |
# redirect GET and HEAD requests to "/foo/" to "/foo" | |
if (request.get? || request.head?) && request.path_info[-1] == "/" | |
newpath = request.path_info.chop | |
if Sinatra::Application.routes["GET"].find {|re,*other| newpath =~ re } | |
redirect to(newpath) | |
end | |
end | |
haml :x404 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment