Stripping Suffixes in H2O

Created on 2020-08-29T05:59:44.531935

Return to the Index

This card can also be read via Gemini.

H2O does not have anything like `mod_rewrite`. You have to use an mruby handler, mangle the URL there and return it via an `x-reproxy-url` header.

A static file rule so the stylesheet bypasses filtering:

/z/quinn.css:
  file.file: /var/www/z/quinn.css
/z/:
  reproxy:on
  mruby.handler: |
    lambda do |env|
      if /\.html$/.match(env['PATH_INFO']) then
        return [399, {}, []] # pass request along
      end
      return [307, {'x-reproxy-url'=>"/z/#{env['PATH_INFO'}.html"}, []]
  file.dir: /var/www/z

Important: the re-proxy URL must be anchored from the server root, even though `PATH_INFO` will be relative to the handler rule. This caused me great annoyance.

What PATH_INFO says: /cke9k5aos00001aisaxp5ie53

What you actually need to return: /z/cke9k5aos00001aisaxp5ie53.html