Redirecting all posts after changing URL structure with htaccess

Within Settings > Permalinks your Custom Structure was set to /%category%/%postname%/ right?

Now you want to set (or you’ve already set) to /%post_id%/ right?

As far as I know (and I’ve also tested) WordPress will 301 redirect all of your posts (from the post type ‘post’) to your new Custom Structure. You won’t need to do a thing.

So if you’ve set the Custom Structure to /%post_id%/ it means that if someone accesses the URL https://domain.com/my-category/my-post-slug they would be redirected to https://domain.com/POST_ID.

After you’ve changed your Custom Structure even if you also change your post slug WordPress will still redirect it correctly.

I don’t know from which WP version this is supposed to work, but just for the record, I’ve tested within 4.7.

If it’s not working for you let me know and I’ll give you another solution.

By the way, I’m supposing your WordPress site URL didn’t change as in your question you just used domain.com.