Problems with 301 Redirect

May 16, 2014 at 4:55 PM
I'm trying to redirect a few old posts to new ones. To do this I'm inspecting the url in the Global.asax and performing the necessary 301. This works for one page, but not for another. It seems that the url for some pages is being interpreted properly, but for other pages it's being interpreted in the format: http://www.domain.com/blog/post.aspx?id=585e32b8-153f-40b6-9d93-b5328bd6db6e.

Here is an example of a page that works:
if (HttpContext.Current.Request.Url.AbsoluteUri.ToLower().Contains("/blog/post/establishing-prizes-for-fantasy-football-leagues.aspx"))
          {
            string newUrl = "http://www.cheatsheetwarroom.com/blog/post/fantasy-award-and-prize-ideas.aspx";
            Response.Status = "301 Moved Permanently";
            Response.StatusCode = 301;
            Response.StatusDescription = "Moved Permanently";
            Response.AddHeader("Location", newUrl);
           Response.End();
          }
For this page, the AbsoluteUri is read as:
http://www.cheatsheetwarroom.com/blog/post/establishing-prizes-for-fantasy-football-leagues.aspx
Here is one that doesn't work:
          if (HttpContext.Current.Request.Url.AbsoluteUri.ToLower().Contains("/blog/post/fantasy-football-scoring-systems.aspx"))
          {
            string newUrl = "http://www.cheatsheetwarroom.com/blog/post/standard-fantasy-football-scoring-system.aspx";
            Response.Status = "301 Moved Permanently";
            Response.StatusCode = 301;
            Response.StatusDescription = "Moved Permanently";
            Response.AddHeader("Location", newUrl);
           Response.End();
          }
In this example, the AbsoluteUri is read as:
http://www.cheatsheetwarroom.com/blog/post.aspx?id=585e39b8-153f-40b6-9d93-b5328bd6db6e
So the redirect doesn't work. Can someone tell me why the urls are being read differently for these two posts?

Thanks.
May 17, 2014 at 10:23 PM
The problem was due to the fact that the first 301 redirect was going from a non-existing post, while the second 301 redirect was from a post I hadn't deleted yet. Once I deleted the post the full, correct URL was passed in the HttpContext.Current.Request.Url.AbsoluteUri property and the redirect worked as planned.