Rewrite rule is catching pages not posts

You are using the pagename query var, so, like the name suggests, you are requesting a page with the specified name and not other type of content/post. If you want the rewrite rule works for all types of post (except attachments), you can use the p query var passing the post_ID as value. See the available query_vars in WP core.

tech