Im having troubles in the “domain.com” url format related to my API calls. Mostly, calls in “domain.com” and “www.domain.com” are generating different sessions values.
What I need is to redirect the user to the right url if the url is “domain.com/a/b/” to “www.domain.com/a/b/”, including the root folder.
I do have a master page, and Im probaly going to check the url in the page load.
Problems:
-
What is the regex to match the “www” in “http://www.domain.com/a/b/c/”?
-
Should I use a insert to fix the url?
string url = Request.Url.AbsoluteUri; if (Regex.Match(url, @"http://(www).com/.*").Success) { Response.Status = "301 Moved Permanently"; Response.AddHeader("Location", url.Insert(8, "www"); }
Thx
Why not use
.BeginsWith("http://www")and.BeginsWith("https://www")? Regex seems overly complicated for this use.