Http_reply_from_files/3 should return 301 Moved Permanently on directories without trailing /

Dear all,

I am trying to get http_reply_from_files/3 from library(http/http_files) to first return a moved (301 Moved Permanently) reply in case the URL to a directory is missing the trailing /.

I was hoping to get this out of the box, since the documentation of http_reply_from_files/3 refers to http_reply_dirindex/3, where this behavior is described. However, the example in the documentation fails to show this behavior.

This is annoying, for example since relative links in index.html pages point to the wrong direction if the user omits the trailing /. Any hints on how to enable this behavior?

Thanks & best regards
Thomas

Dear all,

it seems this is not causing a lot of interest from the community, so I just went ahead and worked on it on my own. In case anybody stumbles over this thread in the future and is interested in the topic, please refer to the pull request shown on https://github.com/SWI-Prolog/packages-http/issues/142 for a fix.

Best regards
Thomas

I’m trying to fully understand what is going wrong, but I failed to reproduce your problem. I’ve added my attempt.

note this is in fact a zip file due to the various different files needed. Download, rename to site.zip and unpack.

site.pl (874 Bytes)

Sorry, I should have added this in the first place… I modified to show what I mean: site2.pl (1.3 KB) From root you can click on sub to move to the subdirectory. This will take you to http://localhost:4000/sub (no trailing /) and serve sub/index.html. Now I modified sub/index.html to include a relative link to sub/file2.html. Clicking this link gives an internal server error. If I open http://localhost:4000/sub/ instead, the link works.