diff --git a/lib/jekyll/commands/serve.rb b/lib/jekyll/commands/serve.rb index 6467c5ab..912f4f62 100644 --- a/lib/jekyll/commands/serve.rb +++ b/lib/jekyll/commands/serve.rb @@ -40,7 +40,7 @@ module Jekyll s.mount( options['baseurl'], - WEBrick::HTTPServlet::FileHandler, + FileHandler, destination, file_handler_options ) @@ -131,6 +131,19 @@ module Jekyll end + # Custom WEBrick FileHandler servlet for serving "/file.html" at "/file" + # when no exact match is found. This mirrors the behavior of GitHub Pages + # and many static web server configs. + require 'webrick' + class FileHandler < ::WEBrick::HTTPServlet::FileHandler + def search_file(req, res, basename) + if file = super + file + else + super(req, res, "#{basename}.html") + end + end + end end end end