Add trailing slash redirections

Fixes #13.
pull/15/head
Thibaut 11 years ago
parent 5ed7722448
commit dec2f5a249

@ -118,15 +118,22 @@ class App < Sinatra::Application
end
end
get %r{\A/(.+?)(?=\-|/)} do |doc|
return 404 unless @doc = settings.docs[doc]
erb :other
end
get '/ping' do
200
end
get %r{\A/(\w+)(\-[\w\-]+)?(/)?(.+)?\z} do |doc, type, slash, rest|
return 404 unless @doc = settings.docs[doc]
if !rest && !slash
redirect "/#{doc}#{type}/"
elsif rest && rest.end_with?('/')
redirect "#{doc}#{type}#{slash}#{rest[0...-1]}"
else
erb :other
end
end
not_found do
send_file File.join(settings.public_folder, '404.html'), status: status
end

Loading…
Cancel
Save