Here's the kernel I'm using with ASP.NET Core 1.1 Url, rewriting middleware for redirection from www. non-www:
var options = new RewriteOptions()
.AddRedirect("^(www\\.)(.*)$", "$2");
app.UseRewriter(options);
and for some reason it is not working. I know that regex is correct. What is wrong here?
Here's the full Configure function:
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
app.UseRequestLocalization(new RequestLocalizationOptions() { DefaultRequestCulture = new RequestCulture("ru-ru") });
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseBrowserLink();
}
else
{
var options = new RewriteOptions()
.AddRedirect("^(www\\.)(.*)$", "$2");
app.UseRewriter(options);
app.UseExceptionHandler("/Home/Error");
}
app.UseStaticFiles();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{action=Index}/{id?}",
defaults: new { controller = "Home" }
);
});
}
source
share