Processing 404 Error Messages

Hi,

Sites of this type are likely to generate a lot of 404 messages as products come and go and I delete and introduce new products. Is there a way to code in the store an automatic 301 redirect to the main page to avoid penalties and reduce the level of annoyance created by these errors among visitors?

If that can not be, can I do anything to cause an automatic 301 redirect to the store's home page?

Thank you