I'm writing a migration using migrate/migrate_d2d to import nodes from one Drupal 7 installation to another.

Currently there are a lot of links on the web that point to articles using the example.com/node/[nid] url. Since the site I'm importing to will eventually replace the current one, I need to make sure those links still point to the correct articles.

How can I preserve nids during the migration, so that the old links that use /node/[nid] still point to the correct articles?

Alternatively, how can I easily make 500,000+ URLs to old nids redirect to their newly migrated counterpart?


2 Answers 2


This is actually easy to do. In the prepare() function of the node migration class, just set the nid and is_new to true:

public function prepare($node, $row) {
  // Preserve old nid so that old links to nodes using /node/nid still work
  $node->is_new = TRUE;
  $node->nid = $row->nid;

Hmmm... with my limited knowledge on this subject my first instinct would be to use the url redirect module to map old urls to new ones, so instead of trying to bend drupal's automatic node id allocation, just map old to new. Should be able to do that easily enough if you've managed to master migrate_d2d!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.