Which is the most efficient and reliable way to redirect all requests to an old domain on IIS to the home page of a new domain on the same server? Our company owns the server, so we can do what we like with it.
One option that pops up is:
using Microsoft.AspNetCore.Rewrite;
WebApplicationBuilder builder = WebApplication.CreateSlimBuilder(args);
WebApplication app = builder.Build();
RewriteOptions rewriteOptions = new RewriteOptions();
rewriteOptions.AddRedirect("https://www.olddomain.com*", "https://www.newdomain.com", statusCode: StatusCodes.Status301MovedPermanently);
app.UseRewriter(rewriteOptions);
app.Run();
Is this going to redirect all requests as I hope, or is there a more efficient and reliable solution?
Is this better done using IIS rules?
<system.webServer>
<rewrite>
<rules>
<rule name="oldDomain.comRedirect" stopProcessing="true">
<match url="(.*)" />
<action type="Redirect" url="https://www.newDomain.com" />
</rule>
</rules>
</rewrite>
</system.webServer>
This is very simple in IIS, you can use URL Rewrite if you want to but it's not necessary.
From within IIS Manager:
You can also disable the old site, add the old domain to the new website, and then use URL Rewrite.