title: Magento: Delete products and 301 redirect to relevant existing page, e.g., it's parent category
body: <p>Anyone have a solution for 301 permanent redirects for deleted products in Magento?</p>
  
  <p>I have a store with 5000 products. 4000 have been sold and will never be back in stock. I want to delete those products b/c I no longer need them and want to clean up/decrease my database, but I need to 301 permanently redirect them to appropriate pages to keep the SEO juice I've built up.</p>
  
  <p>To be clear, I do not want the deleted product pages to be live any more, not even with an Out of Stock message, and I do not want 404 Page Not Founds.</p>
  
  <p>Ideally, I would be able to export the product URL and its lowest-level category page's URL so that I could create 301 redirects via an .htaccess file. But exporting from Magento only exports category IDs, not category names or URLs, so how do I get these programmaticly? Or other solution to this?</p>