If you’ve changed your permalink structure recently and had poop loads of 404s, you can do a few things to fix it:
- Change the permalink structure back (well, why not?)
- Install a permalink fixing plugin
- Have a read of WordPress query rewrite stuff (it’s pretty long ass)
Or you can save yourself a poop load of hassle and by applying a bit of cunning you can simply get around the problem with a tiny bit of code:
{
$n = array(
'[0-9]{4}/[0-9]{2}/[0-9]{2}/([^/]+)/?$' => 'index.php?name=$matches[1]'
);
return $n + $r;
}
add_filter( 'rewrite_rules_array', '_add_rewrite_rules' );
Simply all we do here is set an array key that’s the regex of the structure we want to redirect to the value, so in this case we’re after something like ’2009/06/29/heres-a-post-name’ and this’ll be redirect to ‘index.php?name=heres-a-post-name’. Perfect! You can read up more on WordPress’s query stuff here: http://codex.wordpress.org/Class_Reference/WP_Rewrite.