Skip to content

Instantly share code, notes, and snippets.

@bserem
Last active March 8, 2018 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bserem/60160a3d932ef69ec85ff7b7c1aa3ce8 to your computer and use it in GitHub Desktop.
Save bserem/60160a3d932ef69ec85ff7b7c1aa3ce8 to your computer and use it in GitHub Desktop.
Mass import redirects in Drupal 8 from CSV
#!/bin/bash
i=0
cat redir.csv| while read line
do
let "i++"
rsource=`echo $line | cut -d ',' -f1`
rtarget=`echo $line | cut -d ',' -f2`
redirect='use Drupal\redirect\Entity\Redirect;Redirect::create(["redirect_source" => "'$rsource
if [[ $rtarget = *"http"* ]]; then
redirect+='", "redirect_redirect" => "'$rtarget
else
redirect+='", "redirect_redirect" => "internal:'$rtarget
fi
redirect+='", "language" => "und", "status_code" => "301",])->save();'
#echo $redirect
drush ev "$redirect"
echo $i $rsource' to ' $rtarget ' added.'
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment