fix directory redirect code to be compliant, add test

Previously, a request for a URL like /subdir was causing an exception because the information in the redirect was non-compliant. That's been fixed and a test has been added.