diff --git a/lib/app.rb b/lib/app.rb index 6c2e2982..0ad9732a 100644 --- a/lib/app.rb +++ b/lib/app.rb @@ -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