title: ASP.NET Core 1.1 Url Rewriting - www to non-www
body: <p>Here's the core I use with ASP.NET Core 1.1 Url Rewriting middleware to redirect from www. to non-www:</p>
  
  <pre><code>var options = new RewriteOptions()
      .AddRedirect("^(www\\.)(.*)$", "$2");
  app.UseRewriter(options);
  </code></pre>
  
  <p>and for some reason it doesn't work. I know regex is correct. What's wrong here?</p>
  
  <p>Here's the complete Configure function:</p>
  
  <pre><code>        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 =&gt;
          {
              routes.MapRoute(
                     name: "default",
                     template: "{action=Index}/{id?}",
                     defaults: new { controller = "Home" }
                     );
          });
      }
  </code></pre>