301 Redirect Using PHP & BASH For Static Content Migration

Here is a handy BASH Script for redirecting static content to a new location

Example: redirect foo.html bar.html

This will make foo.html redirect to bar.html and save the old foo.html as foo.html_

#!/usr/local/bin/bash
SOURCE=$1
DEST=$2
OLDSUFFIX="_"
echo "Source: $SOURCE  Dest: $DEST"
if ([ -z $SOURCE ] || [ -z $DEST ]); then {
        echo "usage:  php_redirect [SOURCE] [DEST]";
        echo "Old file will be saved as [SOURCE]$OLDSUFFIX";
}
else {  
        if [ ! -f $SOURCE ]; then
                echo "Source: \"$SOURCE\" does not exist"
        else {  
                mv $SOURCE $SOURCE$OLDSUFFIX
                echo "<?php header(\"Location: $DEST\");" > $SOURCE;
                echo "Success!  $SOURCE is saved as $SOURCE$OLDSUFFIX, $SOURCE is redirected to $DEST";
        }
        fi
}
fi