Skip to content

Instantly share code, notes, and snippets.

Created December 19, 2016 23:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/cb063075ff9ce426ca1a496211492054 to your computer and use it in GitHub Desktop.
Save anonymous/cb063075ff9ce426ca1a496211492054 to your computer and use it in GitHub Desktop.
www to non-www with asp.net core 1.1
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
{
// URL Rewriting
var options = new RewriteOptions()
//.AddRedirect(@"^(https?:\/\/)(www\.)(.*)$", "$1$3");
.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" }
);
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment