I am looking for the .htaccess
regular expression that would redirect the old structure to the new one, the reason i don't want to use plugins is they often have unexpected results when WordPress updates or the author abandon them, I need something that would 301 redirect for a long time reliably.
Old permalink:
https://domain.com/%category%/%postname%/
New Permalink:
https://domain.com/%post_id%/
Note: I am not sure if the rule should consider this but. I also use custom post types which add their slug to the url. So The "category" shows up for normal "post" but on CPT it's just:
https://domain.com/%example-cpt-slug%/%postname%/
I suspect a good rule could work for both cases since /%category%/ and /%example-cpt-slug%/ are something between "/ /".
What I'm not so sure is how can you specify the POST ID (%post_id%/) as a target.
.htaccess
, because the latter can't know the post ID. Take a look at some 301 plugins.