The other day I was asked to help out with some redirection work as a section of one of our old sites was migrated to a new solution with a new database etc. The original site was a combined editorial and jobs site, the new solution just handles the jobs part on our Madgex Job Board Software. In the upgrade process some of our data had been migrated and the Ids had changed. The client had invested quite heavily in SEO work, and so we needed to redirect any requests to the jobs part of the old site to access the same job on the new site. The migration process itself produced us a mapping of old Ids and new Ids, so all I needed was something that enabled me to plug in the old Id and generate the new URL to issue a 301 redirect at. I wanted the change to be as localised as possible, and didn't want to do anything that impacted the functionality of the existing editorial site. After a bit of head-scratching, I decided to make use of a resx file, specifically a local resx file by creating an App_LocalResources folder, and creating a new .aspx.resx file. I populated the resx file with a name value of the Old Id, and a value value of the New Id, and the look-up became straightforward. All I needed to do was catch the Old Id, wrap a newId = GetLocalResourceObject(oldId.ToString()).ToString(); in a try/catch in case the old Id isn't in the resx file and that would do it. I built up a new url and issued a 301 redirect via Response.Status = "301 Moved Permanently"; Response.AddHeader("Location", UriToNewId);All of this code replaced the original code on the editorial site, and redirected any visitors to the new jobs site.
comments powered by Disqus