How to rewrite urls and add trailing slash in dotnet core, Umbraco9+
Just want to achieve if I visit /agenda it rewrites to /agenda/ for example.
We used to to this by adding a rewrite rule in web.config. Nowadays we add rewrite rules by adding piece of middleware and read rewrite.config file to pass to AddIISUrlRewrite()
But because these matchTypes aren't supported anymore, it now adds a trailing slash to all file/directory paths as well, wich of course messes up the whole site.
Unfortunately Umbraco documentation itself doesn't mention this and still says to use this matchType in Umbraco 9+ but again: this doesnt work.
How to rewrite urls and add trailing slash in dotnet core, Umbraco9+
Just want to achieve if I visit /agenda it rewrites to /agenda/ for example.
We used to to this by adding a rewrite rule in web.config. Nowadays we add rewrite rules by adding piece of middleware and read rewrite.config file to pass to AddIISUrlRewrite()
This seems to work for most of our rules, but in .net core matchType="IsFile" and "IsDirectory" don't seem to be supported anymore. (See: https://learn.microsoft.com/en-us/aspnet/core/fundamentals/url-rewriting?view=aspnetcore-3.1#when-to-use-url-rewriting-middleware : "Some of the features of the server modules don't work with ASP.NET Core projects, such as the IsFile and IsDirectory constraints of the IIS Rewrite module. In these scenarios, use the middleware instead.")
Normally we would use this:
But because these matchTypes aren't supported anymore, it now adds a trailing slash to all file/directory paths as well, wich of course messes up the whole site.
Unfortunately Umbraco documentation itself doesn't mention this and still says to use this matchType in Umbraco 9+ but again: this doesnt work.
Does anyone have another solution for this?
Thanks in advance!
Hi Remko
You can list and negate the individual file extensions, and known non front end folders and preview urls...
regards
Marc
Thanks Marc,
This helped me a lot :-)
{URL} didn't seem to work on the server, so I replaced that with {REQUEST_URI} as well.
Greetings, Remko
is working on a reply...