How Do I ... Redirect a Web Page using a CGI-Script

Contents


Introduction

nph-redir is a cgi-script that allows you to redirect your web browser to a site you choose from a pull-down list, just by clicking a button. Because you can put many sites in the pull-down list, while the list only takes up a few lines on the screen, this can save you a significant amount of screen-space.

How to Use nph-redir

To use nph-redir you include a FORM in your web page, with the ACTION /cgi-bin/nph-redir.cgi. The form should have a field, usually a SELECT, with the name dest. The value of this field is the URL to which you wish to be redirected:

<FORM ACTION="/cgi-bin/nph-redir.cgi" METHOD="POST">
Destination URL?
<SELECT NAME="dest">
<OPTION VALUE="http://www.yahoo.com">Yahoo!
<OPTION VALUE="http://www.netscape.com">Netscape
<OPTION VALUE="http://www.cnet.com">c|net
<OPTION VALUE="http://www.microsoft.com">Microsoft
</SELECT>
<INPUT TYPE="SUBMIT" VALUE="Redirect Me!">
</FORM>

The above form will look as follows:

Destination URL?

By clicking on the pull-down list you can select a site. By then clicking on the submit ("Redirect Me!") button, you will be taken to that site.

If you are redirecting to a frameset, you can select a particular frame by putting its name in a field with the name target. An example of redirecting a user to Yahoo, in a frame called main, would look like this:

<form action="/cgi-bin/nph-redir.cgi" method="POST">
<input type="HIDDEN" name="target" value="main">
<input type="HIDDEN" name="dest" value="http://www.yahoo.com">
<input type="SUBMIT" value="Click Here To Visit Yahoo">
</form>

About nph-redir

nph-redir was developed by Jeff Carnahan, <jeffc@terminalp.com>.

 

Disclaimer: The provided instructions are for information purposes only. Neither The University of Western Ontario nor the Division of Information Technology Services assume any responsibility for loss of use or damage to a computer system (including any data or software contained within the computer system) which is the result (directly or indirectly) of the application of these instructions. Any problems, questions or concerns not addressed by these instructions should be directed to the vendor and/or the manufacturer and not to The University of Western Ontario or any of its employees or incumbents.

©2010, The University of Western Ontario. Permission is granted to copy in whole or in part provided that due credit is given to the authors, Information Technology Services, and The University of Western Ontario.

Western provides the best student experience among Canada's leading research-intensive universities.