I know this has been asked before but I haven't seen any simple explanations and I should also add I'm on shared hosting (Plesk). I don't see the URLRewriter utility installed on the server.
Anyway, I rebuilt my 2013 website that did use ASP.NET web forms (with .ASPX extensions). I'd like to be able to redirect my old pages to their new equivalents. i.e.
https://www.findaforum.net/diyfishkeepers-com.aspx
Should now point to:
https://www.findaforum.net/Forums/diyfishkeepers-com/
At the moment the .ASPX pages show this in a red box on a yellow screen:
XML Parsing Error: no element found Location: https://www.findaforum.net/diyfishkeepers-com.aspx Line Number 1, Column 1:
Where does this "come" from?
Incidentally, I'm looking for a quick and easy fix because I don't have too many external links pointing to my site's subpages, but it would be nicer for the user experience to fix it while Google works out I've changed my entire site.
This answer basically works:
How to redirect .ASPX pages to .NET Core Razor page
There's a good link to the URL rewriting regular expressions here: https://isitoktocode.com/post/introduction-to-url-rewriting-using-iis-url-rewrite-module-and-regular-expressions
This is what I've put in Startup.cs:
var options = new RewriteOptions() .AddRedirect(@"ShowCategories.aspx", "/Home/Categories/") .AddRedirect(@"Statistics.aspx", "/Home/TopForums/") .AddRedirect(@"SubmitForum.aspx", "/Home/Submit/") .AddRedirect(@"Help.aspx", "/Home/HelpAndFAQ/") .AddRedirect(@"([0-9a-z-A-Z]+)(.aspx)", "/Forums/$1/"); app.UseRewriter(options);
Note: Make sure you put the specific ones at the top, then the generic ones at the bottom.
I also had some URLs like https://www.findaforum.net/lpsg-com where 'lpsg-com' is a forum name. I added a URL to the home controller to take care of these...
[HttpGet] [Route("{code}")] public ActionResult Unknown(string code) { return RedirectToAction(code, "Forums"); }
1.4m articles
1.4m replys
5 comments
56.9k users