diff --git a/Tesses.WebServer.NetStandard/TessesServer.cs b/Tesses.WebServer.NetStandard/TessesServer.cs
index dd0d5f9..5ca5946 100644
--- a/Tesses.WebServer.NetStandard/TessesServer.cs
+++ b/Tesses.WebServer.NetStandard/TessesServer.cs
@@ -972,7 +972,7 @@ namespace Tesses.WebServer
///
/// directory for server
/// whether to allow listing directory or not (overridable by environment variable with TESSES_WEBSERVER_ALLOW_LISTING=true|false)
-
+ public bool RedirectToRootInsteadOfNotFound {get;set;}=false;
public StaticServer(string path,bool allowListing)
{
_server = new NotFoundServer();
@@ -1070,7 +1070,34 @@ namespace Tesses.WebServer
}
break;
case WebServerPathType.NotFound:
- await _server.GetAsync(ctx);
+ if(RedirectToRootInsteadOfNotFound)
+ {
+ var fileEntry2 = fileHandler.GetPath("/");
+ switch(fileEntry.Type)
+ {
+ case WebServerPathType.File:
+ using(var strm = fileHandler.Open(fileEntry2))
+ await ctx.SendStreamAsync(strm,HeyRed.Mime.MimeTypesMap.GetMimeType(fileEntry.FileName));
+ break;
+ case WebServerPathType.Directory:
+ if(AllowListingDirectories)
+ {
+ DirectoryLister lister=new DirectoryLister();
+ lister.FromDirectory(fileHandler,"/",ctx.OriginalUrlPath);
+ await lister.GetAsync(ctx);
+ }
+ else
+ {
+ await _forbidden.GetAsync(ctx);
+ }
+ break;
+ case WebServerPathType.NotFound:
+ await _server.GetAsync(ctx);
+ break;
+ }
+ }else{
+ await _server.GetAsync(ctx);
+ }
break;
}
}catch(UnauthorizedAccessException ex)