Asp.net mvc 301 redirect from www.domain.com to domain.com?

I accept that doing this at application level is non-desirable as per the comments to the question Installing the HTTP Redirect feature in IIS7 is the best way to do this In our case, other constraints force us to do this at application level Here is the code that we use in global. Asax to perform the redirect: private static readonly Regex wwwRegex = new Regex(@"www\.(?. *)", RegexOptions.

Compiled | RegexOptions. IgnoreCase | RegexOptions. Singleline); protected void Application_BeginRequest(Object sender, EventArgs e) { string hostName = Request.

Headers"x-forwarded-host"; hostName = string. IsNullOrEmpty(hostName)? Request.Url.

Host : hostName; Match match = wwwRegex. Match(hostName); if (match. Success) { string mainDomain = match.

Groups"mainDomain". Value; var builder=new UriBuilder(Request. Url) { Host = mainDomain }; string redirectUrl = builder.Uri.ToString(); Response.Clear(); Response.

StatusCode = 301; Response. StatusDescription = "Moved Permanently"; Response. AddHeader("Location", redirectUrl); Response.End(); } }.

I accept that doing this at application level is non-desirable as per the comments to the question. Installing the HTTP Redirect feature in IIS7 is the best way to do this. In our case, other constraints force us to do this at application level.

Here is the code that we use in global. Asax to perform the redirect: private static readonly Regex wwwRegex = new Regex(@"www\.(?. *)", RegexOptions.

Compiled | RegexOptions. IgnoreCase | RegexOptions. Singleline); protected void Application_BeginRequest(Object sender, EventArgs e) { string hostName = Request.

Headers"x-forwarded-host"; hostName = string. IsNullOrEmpty(hostName)? Request.Url.

Host : hostName; Match match = wwwRegex. Match(hostName); if (match. Success) { string mainDomain = match.

Groups"mainDomain". Value; var builder=new UriBuilder(Request. Url) { Host = mainDomain }; string redirectUrl = builder.Uri.ToString(); Response.Clear(); Response.

StatusCode = 301; Response. StatusDescription = "Moved Permanently"; Response. AddHeader("Location", redirectUrl); Response.End(); } }.

The issue is with the v4.0 ASP.Net extension less URL feature on II6. When trying to redirect from domain.com to www. Htaccss, the site is redirected to http://www.

Axd/52edd456ecd9e8469d7bb00f556e5867/ which is a temp URL the framework puts in during the process and for whatever reason fails to update before the process is completed. I created a new domain to replicate this under www. Domain.com, simply type in domain.com and the issues comes up.

The "application" I put on there is a basic web page with one line of code writing the results to the screen - nothing else. RewriteEngine On RewriteCond %{HTTP_HOST} ^domain.com RewriteRule (.*) http://www. My understanding is that you are using Windows Server 2003 and IIS 6.0.

The following pertains to your configuration: There are only two ways to end up with /eurl.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions