add custom error pages script

this script assumes the following
1) that you a domain set up and proper vhsot directive ( see add domin script )
2) the script give option for URL or folder redirect

#!/bin/bash
clear

url_custom_error_pages ()
{
read -p "Enter your domain name: " d
read -p "Enter the error number : " e
read -p "Enter the url you want the error page  to redirect to " u

if [ -d /websites/"$d" ]; then

         if [  -z "$(sed -n "/\#add_custom_error_page_${d}_from_${e}\#/,/\#add_custom_error_page_${d}_from_${e}\#/p" /usr/local/apache2/conf/extra/httpd_vhost.conf)"  ]; then
sed -i "/\#FEATURES_${d}2631\#/a\#################add_custom_error_page_${d}_from_${e}\#################\n ErrorDocument ${e} http\:\/\/$u \n#################add_custom_error_page_${d}_from_${e}\##################" /usr/local/apache2/conf/extra/httpd_vhost.conf

/etc/init.d/httpd graceful
        else
echo -e "The custom error page already exist "
        fi
else
echo -e "the domain $d does not exist"
fi
}

folder_custom_error_pages ()
{
read -p "Enter your domain name: " d
read -p "Enter the error number : " e
read -p "Enter the foler you want the error page  to redirect to " f

if [ -d /websites/"$d" ]; then

         if [  -z "$(sed -n "/\#add_custom_error_page_${d}_from_${e}\#/,/\#add_custom_error_page_${d}_from_${e}\#/p" /usr/local/apache2/conf/extra/httpd_vhost.conf)"  ]; then
sed -i "/\#FEATURES_${d}2631\#/a\#################add_custom_error_page_${d}_from_${e}\#################\n ErrorDocument ${e} ${f} \n#################add_custom_error_page_${d}_from_${e}\##################" /usr/local/apache2/conf/extra/httpd_vhost.conf

/etc/init.d/httpd graceful
        else
echo -e "The custom erro page alread exist"
        fi
else
echo -e "the domain $d does not exist"
fi
}

read -p " do you want your error page to redirect to url or to specific folder: [ url / folder ] " r

case $r in
url ) url_custom_error_pages
;;
folder ) folder_custom_error_pages
;;
* ) echo -e " please enter ur l or folder "
esac


--

No comments:

Other Articles

Enter your email address: