tags:

views:

275

answers:

3

I'm about to replace a current e-commerce site with a brand new site. Before, a URL to a product was like this: www.example.com/ProductDetails.aspx?ProductID=123

Now it is like this: www.example.com/en-us/product/123/The-greatest-product-in-the-world

My question is: Should the 301 permanent redirect be done in the Application_BeginRequest event of Global.asax or in the Page_Load of my 404 error page? Isn't too late to make a 301 when the 404 loads?

A: 

You should put it in the Application_BeginRequest event and check the URL requested.

You could put it in the Application_Error event as well and check for a 404 but I think that uses up more resources and will be slower.

Spencer Ruport
+1  A: 

You'll want to do it before the browser (or bot) gets the 404 error. That way you make sure search engine bots are going to properly re-index your product pages and any page rank associated with them.

Eric Petroelje
Do I need to set both the Response.Status and Response.StatusCode, or is the latter sufficient?
MartinHN
And do I have to redirect the user to my new URL?
MartinHN
I would set both, but I think the status code is all that's needed. And yes, redirect to the new URL so search engines know where the page has moved to.
Eric Petroelje
A: 

I have done it in the 404 page, but it's a hack -- you can change the response code. The Application_BeginRequest makes a lot more sense. You want to redirect so your old links will expire from search indexing.

Ishmael