Redirecting post IDs to search engine friendly URLs when WordPress is in a new directory

In this instance, I had a client site with static HTML files in the root and a WordPress blog in the /wordpress/ folder. The old site was using the classic ‘website.tld/?p=123’ URL format, where ‘123’ is the ID of the post.

In the rebuild, the point was three fold:

  1. Get all the static HTML pages into WordPress and editable;
  2. Give the blog posts a more useful SEF URL structure; and
  3. Move everything into the domain root (not down in a /wordpress/ folder).

Luckily for me, WordPress does a good job at matching that ‘123’ ID with the new ‘/2015/12/20/fancy-post-stub/’ structure all on its own—if only the query was looking in the correct directory! Continue reading →