Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

ASP.NET Core: URL rewriting does not work with a static file

app.UseRewriter(new RewriteOptions().AddRedirect("login", "login.html")); //works
app.UseRewriter(new RewriteOptions().AddRewrite("login", "login.html", false)); //doesnt work

In the second case i get error 404, page not found. Why?
The file is in the wwwroot directory.

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Be sure call app.UseRewriter before app.UseStaticFiles(), otherwise the RewriteMiddleware might be superseeded by the one in charge of the static files, which could mess up your rewrite rules:

app.UseRewriter(new RewriteOptions().AddRewrite("login", "login.html", false)); 
app.UseStaticFiles();
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading