locked
301 Redirect RRS feed

  • Question

  • User-1023662167 posted

    Hi,

    Our old site was in Joomla and now we have developed a new site in .Net 2.0

    We have to do 301 redirects of old site url to respective new URL's . Please advise how can achieve this, we have more than 100+ pages for which we have to do 301 redirect. 

    We have placed code in global.asax but it lead to stopping ajax controls. we are on godaddy shared hosting. Please help. Thanks

    Wednesday, September 19, 2012 3:02 AM

All replies

  • User-2131369213 posted

    How about this:

    http://weblogs.asp.net/jeffwids/archive/2010/01/31/how-to-301-permanent-redirect-in-asp-net.aspx

    Wednesday, September 19, 2012 4:54 AM
  • User-1023662167 posted

    Hi,

    Thanks for reply. Actually the old site was in Joomla and New site is in .Net. So what we have to do is if user request for old url , it will take him automatically to the new URL for example if user request for www.example.com/warranty ,  it will lead him automatically to www.example.com/test/warranty.aspx

    We have around 198 URL needs to be redirect so SEO would not be affected. We have placed following code for the 301 redirection in global.asax file:

    #region  301 redirect
            if (Request.Url != null)
            {
                // 301-redirect for Page 1 to Page 2
                //string xmlpath = ConfigurationManager.AppSettings["ReadXml"];
                string xmlpath = HttpContext.Current.Request.PhysicalApplicationPath + "xml/301redirect.xml";
                DataSet ds = new DataSet();
                ds.ReadXml(xmlpath);
                DataRow[] dr = ds.Tables["URLS"].Select("OldURL='" + Request.Url.ToString().ToLower() + "'");
                if (dr.Length > 0)
                {
                    string URLOLD = dr[0]["OldURL"].ToString();
                    string NewUrl = dr[0]["NewURL"].ToString();
                    string key = URLOLD;
                    key = key.ToLower();
                    if (Request.Url.ToString().ToLower().Contains(key) == true)
                    {
                        Response.ClearHeaders();
    
                        Response.Status = "301 Moved Permanently";
    
                        Response.AddHeader("Location", NewUrl.ToLower());
    
                        return;
                    }
    
                }
            }
            #endregion
            #region
            string urlChkForLower = Context.Request.RawUrl;
            if (Regex.IsMatch(urlChkForLower, @"[A-Z]") == true)
            {
    
                Context.Response.ClearHeaders();
                Context.Response.Status = "301 Moved Permanently";
                Context.Response.AddHeader("Location", urlChkForLower.ToLower());
            }
            #endregion

    But by applying this , the Ajax controls in website stopped working. How to solve it or is there any other way to implement?

    Thanks

    Wednesday, September 19, 2012 5:18 AM
  • User582086724 posted

    Hi..

    Refer the below link to handle redirect to new url ........

    http://www.dotnetcode.in/2012/06/redirect-from-old-url-to-new-url-link.html

    Monday, October 22, 2012 10:25 AM
  • User108830567 posted

    You can use the HttpRedirect settings using IIS7. This requires admin access to the web server.

    You can also use a HTTP module instead of using global.asax for better performance. The module is configured on your web config and it can applied your URL redirect rules. Cache your rules in memory to avoid database access overhead.

    Monday, October 29, 2012 12:23 PM
  • User-570742420 posted

    If using IIS 7 or higher, the simplest solution I found is to use the httpRedirect element in my web.config. I wrote a small article here: ASP.NET 301 permanent redirects: the best solution

    Tuesday, December 11, 2012 12:38 PM