I'm upgrading my site from D6 to D7, and want to move a section of the site to a better spot. That requires about 10000 redirects. (I use redirect module: https://drupal.org/project/redirect ).

With D7, the redirect table includes a hash ("hash - A unique hash based on source, source_options, and language."). How can I build that, using PHP? I have a textfile with node/# and the old URLs. I can make them into a mysql table.

But while I can do basic PHP, I'm not advanced enough to understand the redirect.module source. The relevant bits are, I understand, lines 399-403:

$redirect->source = $path['original']['alias'];
$redirect->redirect = $path['source'];
$redirect->language = $path['original']['language'];
// Check if the redirect exists before saving.
$hash = redirect_hash($redirect);`

and lines 1069-1081:

function redirect_hash($redirect) {
  $hash = array(
    source' => $redirect->source,
    language' => $redirect->language,
  if (!empty($redirect->source_options['query'])) {
    $hash['source_query'] = $redirect->source_options['query'];
  drupal_alter('redirect_hash', $hash, $redirect);
  redirect_sort_recursive($hash, 'ksort');
  $redirect->hash = drupal_hash_base64(serialize($hash));
  return $redirect->hash;


  • I don't have an answer for you, but in general you should try to leverage the Drupal API, when possible, instead of direct DB access. You should look at the submit handlers for the Redirect module and how everything gets done. Then mirror that in your own code. If you find a solution before you get an answer, you can post it as your own answer.
    – mpdonadio
    Jan 5, 2014 at 15:54

1 Answer 1


Usually there is always a module that can help out.

In your case I recommend Path Redirect Import. It has a bulk import mechanism for redirects via CSV. It supports the Drupal 7 redirect module.

To get the redirects exported from D6 in the right format, check the Path Redirect Export module.

I believe that should do the trick for you.

I hope this helps you.


Your Answer

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

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