Updated handling of subdirectories and redirects.