Closed (won't fix)
Project:
Global Redirect
Version:
6.x-1.2
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
10 Jul 2011 at 18:44 UTC
Updated:
13 Jan 2015 at 14:02 UTC
Jump to comment: Most recent
Comments
Comment #1
essenceofginger commentedWould love to see this too. I need to add over 500 301s as a result of migrating a site from another platform to Drupal, doing them manually one by one is almost certainly a no-go; putting them in the .htaccess is less than ideal as I'd like to take advantage of the module's expiry function.
So... +1 for this request!
Comment #2
nicholasthompsonSee: http://drupal.org/project/path_redirect
I *believe* it has an import feature - if not, the data is stored in a single table and would be a relatively trivial task to import a CSV into it.
Comment #3
essenceofginger commentedYup, that's what exactly we tried to do. We were a bit stumped with the MD5 hash though; seeming as it's not clear how they're generated, we tried to insert them blank. It wouldn't work (there's a unique key constraint on the hash field); so generating a unique MD5 hash for each entry by calculating the MD5 of the source URL seemed to do the trick. Job done!
Script (credit to Dave Tibbs):
#!/bin/bash
while read line; do
fromurl=$(echo $line | cut -f1 -d,)
tourl=$(echo $line | cut -f2 -d,)
md5hash=$(echo -n $line | md5sum | awk {'print $1'})
mysql drupal -Ne "insert into redirect (hash,type,source,source_options,redirect,redirect_options,language,status_code) values ('$md5hash','redirect','$fromurl','a:0:{}','$tourl','a:0:{}','und',0);"
done < $1
To run: ./parse_csv.sh [filename]
Hope this helps anyone else!
Comment #4
stephenward commentedFor those in search of a (very) quick and (very) dirty solution, I wrote this quick script for adding bulk redirects to client sites prior to launching them. Just drop the following code into a temporary file in your Drupal root, navigate to it, and submit a list of redirects. The list should be one redirect per line with the old URL (sans everything up to the base directory) followed by a comma and the new path.
I'm using Drupal 7 for this and it seems to work fine; it may need to be tweaked for Drupal 6. I'd love to see something more elegant added to the module itself, but for now, this script suits my purposes.
Comment #5
wmfinck commentedStephenWard thank you, wish I could buy you a beer!
Comment #6
elmarquis commentedThanks, StephenWard. Did exactly what I needed. A one-off bulk import of 301 redirects.
I occasionally got some errors, so I made one small change to add some error handling and list the ones which were successful and ones which failed.
Most of the time an error was due to a duplicate entry.
Will share the code here in case it helps anyone.
Comment #7
deardagny commentedThanks @StephenWard and @elmarquis. This was a huge help. I owe you beers as well.
Comment #8
Channel Islander commentedHi guys,
Thanks for the script, but I have to report to anyone considering it that it will not work if your source URLs have query strings and/or your aliases have fragment anchors.
Redirect module stores those URL elements in a data hash in the source_options and redirect_options fields in the DB; this script retains them on the URL paths when storing those [via call to redirect_save() ] and thus the redirects do not work.
Comment #9
Channel Islander commentedD'oh, I should have known there would be a module if I just looked harder for it.
https://www.drupal.org/project/path_redirect_import seems to be the solution for this task.