I successfully managed to redirect non-use of www. with my Website domain name - for SSL requirements and to follow Google's recommendation which soon followed increased traffic due to Googles increased willingness to serve the site. However 2 weeks ago my Website went down and supposedly the Global file with the following code was the cause according to my host's administrator. I tried replacing the altered global file with an original but still was unable to get the Website backup, so I decided to make the long needed upgrade to nop 1.05 - which had the website backup in a few hours. But with no redirect. If anyone can view errors in the code please point it out?



<script runat="server">

    void Application_BeginRequest(object sender, EventArgs e)
    {
        NopConfig.Init();
        if (!InstallerHelper.ConnectionStringIsSet())
        {
            InstallerHelper.InstallRedirect();
        }


        if (HttpContext.Current.Request.Url.ToString().ToLower().Contains("http://phoenixdirecttech.com"))
        {
            HttpContext.Current.Response.Status = "301 Moved Permanently";
        }
        HttpContext.Current.Response.AddHeader("Location", Request.Url.ToString().ToLower().Replace("http://phoenixdirecttech", "http://www.phoenixdirecttech"));
}
    

    void Application_Start(object sender, EventArgs e)
    {
        // Code that runs on application startup
        NopConfig.Init();
        if (InstallerHelper.ConnectionStringIsSet())
        {
            TaskManager.Instance.Initialize(NopConfig.ScheduleTasks);
            TaskManager.Instance.Start();
        }
    }
    
    void Application_End(object sender, EventArgs e)
    {
        //  Code that runs on application shutdown
        if (InstallerHelper.ConnectionStringIsSet())
        {
            TaskManager.Instance.Stop();
        }
    }
    
    void Application_Error(object sender, EventArgs e)
    {

        Exception ex = Server.GetLastError();
        if (ex != null)
        {
            //try
            //{
                if (InstallerHelper.ConnectionStringIsSet())
                {
                    LogManager.InsertLog(LogTypeEnum.Unknown, ex.Message, ex);
                }
        }
    }
    
</script>




============================================================================



Also, I own another domain Phoenix-Direct.net that is configured at the host settings to redirect to http://www.phoenixdirecttech.com - which is sometimes mistakenly viewed as duplicate content or Website often causing Google to penalize a Website.  

Would it be correct to use the code below (if it is error free) to redirect the domain name. Or is there a better method rather than a 301?

I was hoping something like this will work:

  if (HttpContext.Current.Request.Url.ToString().ToLower().Contains("http://phoenixdirecttech.com" || "Phoenix-Direct.net"))
        {
            HttpContext.Current.Response.Status = "301 Moved Permanently";
        }
        HttpContext.Current.Response.AddHeader("Location", Request.Url.ToString().ToLower().Replace("http://phoenixdirecttech" || "Phoenix-Direct.net"
"http://www.phoenixdirecttech"));


Will it work?

Thanks sorry it is an extensive post, but once I have working code it will be an excellent reference for all nop commerce users needing a 301 redirect. The Web has endless sites on redirects but most solutions are poor examples of a well executed redirect.



Thanks....
Shannon
Phoenix Direct