If I did not understand .htacess for Apache, and if you are coding in ASP.Net, you are almost certainly using IIS. This way you can use the .htaccess material in your research.
You can use some kind of Rewriter URL for your redirects, but it can get very complicated. If I were you, I would set it as simple as possible and execute your old 301 page redirects in the Page_Load event ie
protected void Page_Load(object sender, System.EventArgs e) { Response.Status = "301 Moved Permanently"; Response.AddHeader("Location","http://www.domainname.com/new-page.aspx"); }
For your canonical redirect (not from www to www) you can do something like this in the Global.asax file in Application_BeginRequest to detect a non www variant.
if (HttpContext.Current.Request.Url.ToString().ToLower().Contains( "http://mysite.com")) { HttpContext.Current.Response.Status = "301 Moved Permanently"; HttpContext.Current.Response.AddHeader("Location", Request.Url.ToString().ToLower().Replace( "http://mysite.com", "http://www.mysite.com")); }
(this is not my code derived from here )
This is what I would like to do anyway - it is useful in order to be clear and to keep you away from any strange configuration of the web server, which I sometimes find in the black box.
source share