Forum Moderators: open
I want to redirect any incoming request in my site that calls a page that is not using the www prefix to the one with the prefix.
I've just come with this solution :
protected void Application_BeginRequest(Object sender, EventArgs e)
{
string serverName = Request.ServerVariables["SERVER_NAME"];
string destURL = Request.ServerVariables["URL"];if (serverName.IndexOf("example.com") == 0)
{
Response.StatusCode = 301;
Response.RedirectLocation = "http://www.example.com"+destURL;
}
}
Using .Net/IIS, is this the "correct" way to do it?
Any other idea?
[edited by: Xoc at 7:48 am (utc) on May 26, 2005]
In any case, there is a way to do this with pure IIS. See posting #9 in this thread: [webmasterworld.com...]