Created
December 19, 2016 23:24
-
-
Save anonymous/cb063075ff9ce426ca1a496211492054 to your computer and use it in GitHub Desktop.
www to non-www with asp.net core 1.1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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