I've recently launched a new site for a client. Their old site contained a lot of product pages with url parameters such as id=0123.
To try and alleviate people following dead links from Google etc I have implemented a system that looks up the id parameter against their old database, fetches the name of the product and then looks it up in the exp_channel_data table. If a match is found I have a 301 redirect at the top of the 404 template to send the visitor to what is hopefully the correct page.
If no match is found then the 404 page displays (though I may add some other sort of guessed lookup based on some other criteria later).
My question is, will that 301 get sent back to Google BEFORE the 404 response code generated by hitting the 404 template. Will the above method have the desired effect of telling Google that pages have moved to different URLs?