0

I want to import content from a legacy system into Drupal using the migrate module. The URL structure is going to change.

Some of the content has links pointing to the old content and there are also embedded images with soon to be outdated links.

After migrate is done I'll have a mapping from old urls to new urls and should be able to run a custom script. This script would check for all nodes with old urls and replace it with the new urls and then just node_save() it.

Is this a good approach or is there a better solution?

Btw, I'm also planning on setting up a simple php site under the domain to 302 redirect old urls to the new url.

1

Drupal has a built-in API that allows to preserve the data as it has been input but modify its display. It is called the Input Filter system, and it is used to strip markup, generate links and even preprocess Markdown into HTML (using contrib modules). See http://api.drupal.org/api/drupal/modules%21filter%21filter.api.php/function/hook_filter_info/7

This is the proper way to do it, since it is not destructive of the actual data.

1

Writing a script that does a node_load(), search/replace, and then node_save() is definitely the best way to go about it, and I would argue that it is also the "proper" way to handle the situation. If you go with this approach, you can refine and/or alter the script each pass to account for differences in the URLs.

In the past, I have

  • Use rewrites in .htaccess
  • Done search/replace on a database backup file
  • Put search/replace in a preprocess_page

to handle the situation, and all of these are not ideal, mainly because of slight variations in URL structure.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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