redirect any category in URL to the ID and post-name only – hundreds of pages affected

I have many articles linked from external sites without categories. They end up with a 404 not found. A minor migration was done a long time ago and just noticed the 404s.

One of many examples:

incorrect:
wrestleview.com/20060-update-on-joey-mercury-and-his-wwe-status

Correct:
wrestleview.com/wwe-news/20060-update-on-joey-mercury-and-his-wwe-status

I want when people click on a link with no category to automatically redirect to the ID and post name. Since there is always a unique ID to each post. Can this be done through htaccess or functions.php? I cannot do a 301 redirect manually, I have over 1000 links affected by this.

Thanks

Read more here:: redirect any category in URL to the ID and post-name only – hundreds of pages affected

Leave a Reply

Your email address will not be published. Required fields are marked *