如何设置路由"directory"默认文件



我可以为http服务器创建.directory()路由,例如在/路径上,但它只通过文件的直接链接提供文件,如/index.html。如何使其从/重定向到/index.html

使用.htaccess文件进行相同操作。

Options +FollowSymlinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain.co.uk [NC]
RewriteRule ^(.*)$ http://www.domain.co.uk/$1 [R=301,NC]
RewriteRule ^index.html$ http://www.domain.co.uk/ [R=301,L]

经过一些实验,我找到了对我有效的解决方案

routes.file("/", destinationDir + File.separator + "index.html");
routes.directory("/", Paths.get(destinationDir);

这是因为在文件的情况下,路由器需要完全匹配的路径,并且在执行目录前缀比较的情况下。