Tag Archives: wp-cli

Converting EPS Redirects to Nginx Redirects

EPS exports as a CSV, with the fields redirect type, incoming URI, outgoing URL or post ID, number of hits so far. If the incoming URL has commas, it doesn’t properly escape them, so that needs to be checked by grepping for lines with more than 3 commas:
egrep ‘(.*,){4,}’ ~/Downloads/2016-08-24-redirects.csv

The redirects csv should also be checked for spaces, parens, and ? in the URIs, and the spaces should be converted to %20 before running the script, and parens to \(.

eps2nginx.sh:

CSV=/tmp/eps-redirects.csv
for uri_redir in $(cat $CSV | awk -F, '{ print $2"," $3 }'); do
uri=$(cut -d, -f1 <<< "$uri_redir") redir=$(cut -d, -f2 <<< "$uri_redir") case $redir in ''|*[!0-9]*) ;; *) redir=$(wp post list --post__in=$redir --field=url 2> /dev/null);;
esac

echo "rewrite ^/${uri}$ $redir permanent;"
done