aspnet / StaticFiles

[Archived] Middleware for handling requests for file system resources including files and directories. Project moved to https://github.com/aspnet/AspNetCore
Apache License 2.0
114 stars 72 forks source link

Add option to disable appending trailing slashes #187

Closed shravan2x closed 6 years ago

shravan2x commented 7 years ago

As per the title, I propose a new AppendTrailingSlash option.

The docs at https://docs.microsoft.com/en-us/aspnet/core/fundamentals/static-files currently state that UseDefaultFiles and UseDirectoryBrowser will take the url http://<app>/StaticFiles without the trailing slash and cause a client side redirect to http://<app>/StaticFiles/ (adding the trailing slash). Without the trailing slash relative URLs within the documents would be incorrect.

However, this is not always true. For example, consider a file that has all its links as absolute. In this case, the file would work correctly even without a trailing slash.

Many sites like https://stackoverflow.com and https://github.com make trailing slashes optional. In a similar interest, StaticFiles should allow users to do this. Disabling trailing slashes for MVC and being forced to use them by StaticFiles only causes confusion as to which links send 301s for this.

Users who wish to make trailing slashes optional across their entire website could potentially use this option in conjunction with some other AbsoluteLinkConverterMiddleware.

aspnet-hello commented 6 years ago

This issue was moved to aspnet/Home#2449