Redirection Question

Hi, I have a lot of products with an inventory of 1 and gone when they are sold. Could I make the detail page link of those product redirect to the category they were in once they are sold?

Example: some camera link redirect to electronics once it is sold and gone.

The idea is to redirect the user to the category if they come from Google by clicking on a product link that isn't available anymore.

Thank you,


Any suggestions?