Refactor index generation

These are not really utility functions anymore :)
Fix routing

We must use the hostpath dispatch to prevent automatic redirects from
foo to foo/, and we should match whole URLs.