(gs):Create a frame redirect
- This page was last modified on April 12, 2011, at 18:19.
From (mt) Community Wiki
Overview
A frame redirect is one way to make a web page available under many URLs. This article will guide you to do this for your (gs) Grid-Service.
Requirements
Before you start, be sure to read through these instructions completely.
This article has the following dependencies:
- (gs):SSH connection
- Familiarity with (gs):Common SSH commands
- (gs):FTP and SFTP
Instructions
This article is provided as a courtesy and is not supported by (mt) Media Temple.
Use at your own risk.
-
Save the following in plain text:
iredirect.sh
#!/bin/sh #clear #echo "Make sure you are running this script from the customers' domain html folder." #read -p "Proceed? [y/n] : " proceedoption #if [ "$proceedoption" = "n" ] || [ "$proceedoption" = "N" ] #then # echo "" # echo "Aborting..." # echo "" # exit 0; #fi clear #Determine the current site ID and get the domain list SITEID=`pwd | awk -F/ '{print $3}'` domainlist=`ls /home/$SITEID/domains/ | grep -v .gridserver.com` count=0 for word in $domainlist; do if [ $word != "." ] then if [ $word != ".." ] then count=`expr $count + 1` echo $word >> domainlist.lst fi fi done; echo "+======================================================+====================+" echo "| Welcome to automated frame redirect creator. Please select a domain name: |" echo "+=======================================================+===================+" echo "" DOMAINS=(`cat domainlist.lst`) rm -f domainlist.lst i=0 x=0 while (( $i<$count)); do x=`expr $i + 1` echo "$x - ${DOMAINS[i]}" let i++ done; echo "" echo "Total domains (including sub-domains): $count" echo "" # Let`s make the user input the domain number. dummy=0 read -p "Please input the number of the domain (EXIT to quit) : " USERSCRIPT # Check to see if the input is numeric or "EXIT" testing=`echo "$USERSCRIPT" | egrep "^[0-9]+$"` if [ "$USERSCRIPT" != "EXIT" ]; then if [ ! "$testing" ]; then echo "" echo "Invalid input. Please enter either the number of a domain, or "EXIT" to quit. Please run the script again." echo "" exit 0; fi else clear echo "Thank you for using the automated frame redirect creator script. Goodbye."; echo "" exit 0; fi # Check to see if input is within the domain number array range ACTUALSCRIPT=`expr $USERSCRIPT - 1` compare_result=`echo "$ACTUALSCRIPT<$dummy" | bc` compare_result2=`echo "$USERSCRIPT>$count" | bc` if [ "$compare_result" == "1" ]; then echo "" echo "Invalid domain selection. The number you have entered does not belong to any domain. Please run the script again." echo "" exit 0; fi if [ "$compare_result2" == "1" ]; then echo "" echo "Invalid domain selection. The number you have entered does not belong to any domain. Please run the script again." echo "" exit 0; fi # Figure out which domain we are talking about here choice=${DOMAINS[$ACTUALSCRIPT]} echo "" echo "Checking whether or not index.htm exists in target domain..." echo "" thedirectory2="/home/$SITEID/domains/$choice/html" thedirectory="/home/$SITEID/domains/$choice/html" outfile="/home/$SITEID/domains/$choice/html/index.htm" outfile2="/home/$SITEID/domains/$choice/html/index.html" outfile3="/home/$SITEID/domains/$choice/html/.htaccess" if [ -f "$thedirectory2" ]; then echo "It appears that there is a 'symbolic link' pointing the HTML folder of your website elsewhere." read -p "Remove it? [y/n] : " removesymlink if [ "$removesymlink" = "n" ] || [ "$removesymlink" = "N" ] then clear echo "Goodbye." exit 0; fi rm -f /home/$SITEID/domains/$choice/html fi if [ ! -d "$thedirectory" ]; then mkdir /home/$SITEID/domains/$choice/html fi if [ -f $outfile ] || [ -f $outfile2 ] || [ -f $outfile3 ] then echo "An index file (or a .htaccess file) already exists in the HTML folder of the specified domain." read -p "Okay to overwrite & backup original(s)? ( y/n ) : " answer if [ "$answer" = "n" ] || [ "$answer" = "N" ] then echo "Aborting..." echo "" exit 0; fi # Clever backup option - add exact date to filename, but replace spaces and : with diff chars xD TODAY=$(date) thestring=`echo $TODAY | sed 's/ /_/g'` thestring2=`echo $thestring | sed 's/:/./g'` if [ -f $outfile ]; then mv /home/$SITEID/domains/$choice/html/index.htm /home/$SITEID/domains/$choice/html/index.htm.backup.$thestring2 fi if [ -f $outfile2 ]; then mv /home/$SITEID/domains/$choice/html/index.html /home/$SITEID/domains/$choice/html/index.html.backup.$thestring2 fi if [ -f $outfile3 ]; then mv /home/$SITEID/domains/$choice/html/.htaccess /home/$SITEID/domains/$choice/html/.htaccess.backup.$thestring2 fi fi echo "Proceeding with the script..." touch /home/$SITEID/domains/$choice/html/index.htm echo "" echo "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01//EN' 'http://www.w3.org/TR/html4/strict.dtd'> <html lang='en'> <head> <script language='JavaScript'> <!-- function calcHeight() { //find the height of the internal page var the_height=document.getElementById('glu').contentWindow.document.body.scrollHeight; //change the height of the iframe document.getElementById('glu').height=the_height; } //--> </script> <style type='text/css'> html, body, div, iframe { margin:0; padding:0; height:100%; } iframe { display:block; width:100%; border:none; } </style>" > /home/$SITEID/domains/$choice/html/index.htm read -p "Enter the title of the frame redirect (website) : " webtitle echo "<title>$webtitle</title> </head> <body style='margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px;'>" >> /home/$SITEID/domains/$choice/html/index.htm read -p "Enter the redirect domain (include http:// or https://) : " thedomain echo "<iframe src='$thedomain' id='glu' width='100%' height='100%' onload='calcHeight();'></iframe> </body> </html>" >> /home/$SITEID/domains/$choice/html/index.htm echo "" echo "All done! :)" echo "" - Upload this file to your (gs) to the /domains/example.com/html/ directory.
- Connect via SSH and cd to the location of the file.
cd /domains/example.com/html/ - Next, we'll run the script:
sh iredirect.sh
- Follow the prompts and you're all set.