How can I rewrite old attachment URLs?

Figured it out! The function I needed to hook is called “the_content”, because that’s the post content that is pulled directly from the database.

I added this code into the functions.php file for my theme.

function force_https_the_content($content) {
  if ( is_ssl() )
  {
    $content = str_replace( 'src="http://', 'src="https://', $content );
  }
  return $content;
}
add_filter('the_content', 'force_https_the_content');