After changing permalink structure, How to redirect attachment url to old parent post url

After changing your permalink structure, you need to refresh the settings in your Yoast plugin.

  1. After changing your WordPress permalink settings, go back to the Permalinks section for Yoast (Yoast SEO => Permalinks).
  2. Uncheck the box to “Redirect attachment URL’s to parent post URL.”
  3. Click Save.
  4. Check the box again.
  5. Click Save again.

This should reset the permalink structure as identified by the Yoast plugin, and your attachment pages should redirect properly now.