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:

  file.file: /var/www/z/quinn.css
  mruby.handler: |
    lambda do |env|
      if /\.html$/.match(env['PATH_INFO']) then
        return [399, {}, []] # pass request along
      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