How to change the WordPress permalink structure to remove dates from the URLs

Switching the permalink structure from /year/month/post-slug to just /post-slug is easy by going to Settings > Permalinks and choosing “Post name”:

But you don’t want any links to your old URLs to end up generating a 404, negatively affecting SEO.  To fix this you’ll want to add in a redirect into your .htaccess file similar to: