aspnet / BasicMiddleware

[Archived] Basic middleware components for ASP.NET Core. Project moved to https://github.com/aspnet/AspNetCore
Apache License 2.0
169 stars 84 forks source link

Redirect to HTTPS always with WWW #299

Closed mdmoura closed 6 years ago

mdmoura commented 6 years ago

I am trying to do the following in ASP.NET Core 2.0:

  1. Redirect HTTP to HTTPS;
  2. Redirect Non WWW to WWW.

I added the following to Startup:

  rewriteOptions
    .AddRedirectToHttps()
    .AddRedirect("^(https?://)(?!www[.])(.*)$", "$1www.$2");

The redirect to HTTPS is working but Non WWW to WWW is not working.

Am I missing something?

Is there a predefined way to redirect Non WWW to WWW and BTW also WWW to Non WWW?

I think this would be a really useful feature.

Tratcher commented 6 years ago

Closing as a duplicate of https://github.com/aspnet/BasicMiddleware/issues/194, https://github.com/aspnet/BasicMiddleware/pull/297