'Wordpress Permalink Redirect "/%postname%/" to "/%postname%-%post_id%.html"

We changed to our wordpress site's permalink structure from "/%postname%/" to "/%postname%-%post_id%.html". For example from "site.com/post" to "site.com/post-12345.html". We are using also AMP version of site and there are links' AMP versions like "site.com/amp/post-12345.html".

There are a lot of different examples with different variations of permalink redirect on internet. But we can not find a redirect way. As we understand it is not possible with htaccess. We tried a lot of functions.php codes that we finded from StackOverflow and other sites, but the redirect could not work. As we say there are a lot of examples on google but any of these is not the same to our permalink redirect structure.

We find some codes from a Chinese site about Scott Yang's Permalink Redirect plugin which is deleted from WP repository. The normally there is not a plugin version of this but we used these codes like a plugin. It has worked for some conditions. But for some link like AMP it gives error and plugin's settings are not stable.

How can we redirect our links correctly with amp and without any loop?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source