Lighttpd url.redirect and changing WordPress permalink structure

Changing Permalink Structure

I used to use the Date and Name permalink structure for my blog:

https://johnsiu.com/index.php/2016/10/13/sample-post/  

But I think it is kind of long and want to shorten it, and change it to Post name structure:

https://johnsiu.com/index.php/sample-post/  

Changing that is as easy as a few clicks in WordPress setting. All existing and future posts will have the new Post name structure.

Issue

However, after I uploaded the new sitemap to Google Webmaster Tool, and start checking my site information, especially Links to Your Site under Search Traffic, I noticed a big issue.

After the permalink structure change, all the links out there with the old structure become broken! Not good!

Solution

Solution? Lighttpd Url.redirect

Since Date and Name permalink format is well structured, the redirect rules is easy:

url.redirect = (

"^/index.php/\d{4}/\d{2}/\d{2}/(.*)$" => "/index.php/$1"

)