[wp-hackers] Content Migration from MT to WP - Redirects
Otto
otto at ottodestruct.com
Tue Oct 11 18:17:15 UTC 2011
On Tue, Oct 11, 2011 at 12:55 PM, Brian Fegter <brian at fegter.com> wrote:
> I'm working on a very large site that is built on Movable Type. We've
> created MT templates that output proper WXR and the import is working great
> in WP. What is the best practice for setting 301 redirects from old > new
> permalink structure? The domain is not changing so we can't use MT templates
> to do the redirects. Just wanted to get some collective wisdom before I
> tackle this.
Step 1: Just try it as is and see what happens. WordPress's canonical
redirection is pretty darned clever in some ways, and it often can
guess the right thing to serve out of the box.
Step 2: If the built in canonical redirection isn't able to detect and
redirect accordingly, then you can add your own code to discover and
handle the redirections. The way you do this is with the
redirect_canonical filter.
add_filter('redirect_canonical','my_redirects',10,2);
function my_redirects($redirect_url, $requested_url) {
// do stuff
return $redirect_url;
}
The function gets the $requested_url, which is what the person asked
for, and it returns the $redirect_url, which is what WordPress thinks
it should serve.
If the $redirect_url is false, then WP will not redirect and will go
to 404 instead. But if the $redirect_url is a normal URL string, then
it will issue a 301 redirect to that string. So if you change that
$redirect_url before returning it, you can make it redirect elsewhere.
So if you can write some code to do the mapping from the old URL to
the new ones, you can make a plugin that has that mapping and then
hook it in using this filter. Voila, instant 301 handling.
-Otto
More information about the wp-hackers
mailing list