Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

How to cgi redirect?

 [1/24] from: jason::cunliffe::verizon::net at: 22-Oct-2002 13:51


How to redirect immediately to a URL in cgi script if a condition is met? someflag: cgi-obj/someflag if someflag [redirect-to http://sometime.com/somepage.html] ^^^^^^^^^^^ thanks ./Jason

 [2/24] from: hallvard:ystad:helpinhand at: 22-Oct-2002 20:11


You just have to check for that condition before you finish printing out the headers. Then you can do a 304 redirect or whatever you please. ~H Dixit Jason Cunliffe (19.51 22.10.2002):

 [3/24] from: micael:gullmes:telenor:se at: 22-Oct-2002 23:08


Heres one way of doing it, don't know if that's what you are looking for: html_redirect: func [ {Creates the first part of a HTML page to be redirected} title [string!] "HTML title of the page" seconds [integer!] "Number of seconds before redirect" url [string!] "URL to redirect to" ][ print rejoin ["Content-Type: text/html^/"] print rejoin [{<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">} newline {<HTML><HEAD><META HTTP-EQUIV="Refresh" CONTENT="} seconds ;URL url {"><TITLE>} title </TITLE> newline </HEAD> <BODY> ] ] html_redirect "Test page" 0 "http://www.redirpage.com/" Brgds /Micael -----Ursprungligt meddelande----- Fr=E5n: Jason Cunliffe [mailto:[jason--cunliffe--verizon--net]] Skickat: den 22 oktober 2002 19:52 Till: [rebol-list--rebol--com] =C4mne: [REBOL] How to cgi redirect? How to redirect immediately to a URL in cgi script if a condition is met? someflag: cgi-obj/someflag if someflag [redirect-to http://sometime.com/somepage.html] ^^^^^^^^^^^ thanks ./Jason

 [4/24] from: jason:cunliffe:verizon at: 22-Oct-2002 16:38


Hallvard Ystad wrote:
> You just have to check for that condition before you finish printing out the > headers. Then you can do a 304 redirect or whatever you please.
Sorry, what's 304 and how do you suggest to handle that in a Rebol cgi-obj? Meanwhile, I solved the redirect this way: someflag: cgi-obj/someflag if someflag [ print rejoin [{<SCRIPT>location.href="} someurl {"</SCRIPT>}] ] thanks ./Jason

 [5/24] from: al:bri:xtra at: 23-Oct-2002 10:37


Jason wrote:
> How to redirect immediately to a URL in cgi script if a condition is met? > someflag: cgi-obj/someflag > if someflag [redirect-to http://sometime.com/somepage.html]
This is from my Wiki.r script: See-Other: func [URL [url!]] [ print rejoin [ Rebol/options/cgi/server-protocol " 303 See Other" newline "Location: " URL newline ] quit ] And used like: Script_URL: join make url! compose [ http (join Rebol/options/cgi/server-name Rebol/options/cgi/script-name) ] #"?" See-Other rejoin [Script_URL File] I hope that helps! Andrew Martin

 [6/24] from: rebologue::yahoo at: 22-Oct-2002 14:39


Jason and Micael have shown some examples of redirects that rely on the client browser. I don't think that's what they want, though. If you can, steer clear of client redirects, due to the well-documented negatives of this approach (e.g., conflicts with the browser Back button). Can a CGI guru please provide a working code example for a server-side redirect? That's really the recommended solution. I'll add the Q&A to the REBOL FAQ project. Regards, Ed --- Gullmes Micael <[Micael--Gullmes--telenor--se]> wrote:

 [7/24] from: chris:langreiter at: 23-Oct-2002 0:20


> How to redirect immediately to a URL in cgi script if a condition is met?
print rejoin ["Location: " url newline]

 [8/24] from: andreas:bolka:gmx at: 22-Oct-2002 23:48


Tuesday, October 22, 2002, 9:38:04 PM, Jason wrote:
> Sorry, what's 304 and how do you suggest to handle that in a Rebol > cgi-obj?
if someflag [ print join "Location: http://new/url" newline quit ] (normal) cgi's don't survive more than a request, so the 'quit does not hurt. if you're working with fcgi or similar stuff, you'll have to ensure, that your script finishes execution after the header has been written. -- Best regards, Andreas mailto:[andreas--bolka--gmx--net]

 [9/24] from: jurgens:akcorp at: 22-Oct-2002 15:46


Just send a location field in the HTTP header response where you would normally send the "Content-type" information. Here is a REBOL CGI script that should redirect to the REBOL Web site: #!c:\rebol\rebolcmd.exe -cs REBOL[] print "Location: http://www.rebol.com/" print "" This has to be send as part of the header response before anything else gets output or it will output to the Web page instead of being interpreted as part of the HTTP header. HTH, Burt Ed O'Connor wrote:

 [10/24] from: jjmmes:yaho:o:es at: 23-Oct-2002 1:36


This is my redirect function. Local urls only ! ;=============================================== redirect: func [ rel-url [string!] ][ print "HTTP/1.1 302 : Moved temporarily" print rejoin [ "Location: " rel-url ] print "^m^j" ] redirect "/"

 [11/24] from: hallvard:ystad:helpinhand at: 23-Oct-2002 20:11


Hi again I'm too late. Not doing any rebol at work anymore, since I am no longer doing computing. Teaching literature is cool, but I miss rebol... Andrew Martin and [jjmmes--yahoo--es] explained good enough, I think. 304 and 303 are http redirect headers. Bye ~H Dixit Jason Cunliffe (22.38 22.10.2002):

 [12/24] from: warp:reboot:ch at: 24-Oct-2002 3:50


Hello all 8), I'm actually using this same function but I have a real big and nasty problem: Every redirect I do I get an extra rebol process not quitting and when there are about 20 of them I get a 500 error from apache. This is from the console: [localhost:~/rebol/CORE] warp% ps -auxc | grep rebol | grep -v "grep" www 879 0.0 0.0 2160 120 ?? S 6:33AM 0:00.00 rebol www 883 0.0 0.0 2160 120 ?? S 6:33AM 0:00.00 rebol www 885 0.0 0.0 2160 120 ?? S 6:33AM 0:00.00 rebol www 910 0.0 0.0 2160 120 ?? S 6:35AM 0:00.01 rebol www 1010 0.0 0.0 2160 120 ?? S 7:22AM 0:00.00 rebol www 1014 0.0 0.0 2160 120 ?? S 7:22AM 0:00.01 rebol www 1016 0.0 0.0 2160 120 ?? S 7:22AM 0:00.00 rebol www 2247 0.0 0.0 2160 120 ?? S 12:15PM 0:00.01 rebol www 2257 0.0 0.0 2160 120 ?? S 12:17PM 0:00.00 rebol www 2261 0.0 0.0 2160 120 ?? S 12:17PM 0:00.00 rebol www 2263 0.0 0.0 2160 120 ?? S 12:17PM 0:00.01 rebol [localhost:~/rebol/CORE] warp% I'm on Mac OSX. If this is a bug of the mac /core version what is the best way to monitor those process and kill them ?? Thanks a lot and 'vive la rebolution!'. Will Arp [Warp--reboot--ch] [23.10.2002 0:20 "Christian Langreiter" [chris--langreiter--com]]

 [13/24] from: al:bri:xtra at: 24-Oct-2002 15:57


Will wrote:
> I'm actually using this same function but I have a real big and nasty
problem:
> Every redirect I do I get an extra rebol process not quitting and when
there are about 20 of them I get a 500 error from apache. Perhaps the script doesn't have 'quit have the redirect? Or doesn't print a blank line? Andrew Martin ICQ: 26227169 http://valley.150m.com/

 [14/24] from: jason:cunliffe:verizon at: 23-Oct-2002 22:39


hmmm... for some reason I still could not get that one [Andreas] to work. But these two are both ok [Linux]: ;#1 simple insert anywhere.. print rejoin [ {<SCRIPT>location.href = "http://somesite.com/somepage.html"</SCRIPT>} ] ;#2 Thanks to "Gullmes Micael" <[Micael--Gullmes--telenor--se]> html_redirect: func [ {Creates the first part of a HTML page to be redirected} title [string!] "HTML title of the page" seconds [integer!] "Number of seconds before redirect" url [string!] "URL to redirect to" ][ print rejoin ["Content-Type: text/html^/"] print rejoin [{<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">} newline {<HTML><HEAD><META HTTP-EQUIV="Refresh" CONTENT="} seconds ";URL=" url {"><TITLE>} title </TITLE> newline </HEAD> <BODY> ] ] html_redirect "Test page" 0 "http://www.redirpage.com/" I am using Micael's now. Tell me what happens on your OS when you try it? ./Jason

 [15/24] from: warp:reboot:ch at: 24-Oct-2002 13:59


Hi Andrew, I checked both, I have newline and quit. Is it OSX related ? Here is a dump of what the server returns: ********* HTTP/1.1 302 Found Date: Thu, 24 Oct 2002 11:44:26 GMT Server: Apache/1.3.26 (Darwin) PHP/4.2.3 Set-Cookie: id=[t 1]; path=; domain=127.0.0.1; Location: http://127.0.0.1/admin/index.j Keep-Alive: timeout=15, max=95 Connection: Keep-Alive Transfer-Encoding: chunked Content-Type: text/html; charset=iso-8859-1 d5 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <HTML><HEAD> <TITLE>302 Found</TITLE> </HEAD><BODY> <H1>Found</H1> The document has moved <A HREF="http://127.0.0.1/admin/index.j">here</A>.<P> </BODY></HTML> 0 HTTP/1.1 200 OK Date: Thu, 24 Oct 2002 11:44:27 GMT Server: Apache/1.3.26 (Darwin) PHP/4.2.3 Keep-Alive: timeout=15, max=100 Connection: Keep-Alive Transfer-Encoding: chunked Content-Type: text/html <html> <head> <meta http-equiv="content-type" content="text/html;charset=ISO-8859-1"> .. *********** Thanks and have a nice day. Will Arp [warp--reboot--ch] [24.10.2002 4:57 "Andrew Martin" [Al--Bri--xtra--co--nz]]

 [16/24] from: jason:cunliffe:verizon at: 24-Oct-2002 5:35


While we are on the topic, does anyone know what is the browser dependency for this? onClick="document.location.href=http://somesite.com/somepage.html" Javascript? Will it it work everywhere, or only post 4.x browsers? thanks all, this has been a very helpful thread ./Jason

 [17/24] from: warp:reboot:ch at: 24-Oct-2002 15:58


Correction to last post, sorry 8) You my find an answer here: .. Document.location.href: http://www.insidedhtml.com/tips/functions/ts14/page1.asp

 [18/24] from: rebologue:ya:hoo at: 24-Oct-2002 6:31


Hi Jason-- With that simple Javascript expression, you should be safe for browsers that support Javascript 1.0 and higher (assuming users have it enabled, of course). Here's a list of Javascript version history for Netscape and IE: Netscape Navigator 2 - JavaScript 1 Netscape Navigator 3 - JavaScript 1.1 Netscape Navigator 4 - JavaScript 1.2 Netscape Navigator 4.05 - JavaScript 1.3 Internet Explorer 2 - no JavaScript support Internet Explorer 3.x - partial JavaScript 1 support, depending on platform. Internet Explorer 4 - partial JavaScript 1.1 support I don't know much about support on Opera, maybe their website offers information on that. Some more recommendations: Consider changing the DOM reference to window.location or just location.href (IIRC, location is higher in the DOM than document) -- onClick="location.href='http://somesite.com/somepage.html'" Note that if this page is in a frameset, you'll may need to change that to top.location if you want the frameset to be redirected and not just the page. Tip: To avoid mangling the functionality of the browser Back button (due to the redirect), use the replace function instead: <script language="JavaScript"> <!-- if (document.images) location.replace('http://somesite.com/somepage.html'); else location.href='http://somesite.com/somepage.html'; //--> </script> I wish more sites would use this technique. Finally, follow your script with a "noscript tag" for users that don't have Javascript enabled -- <noscript> <meta http-equiv="refresh" content="0;URL=http://somesite.com/somepage.html"> </noscript> Hope this helps. Regards, Ed --- Jason Cunliffe wrote:

 [19/24] from: warp:reboot:ch at: 24-Oct-2002 15:51


[24.10.2002 11:35 "Jason Cunliffe" [jason--cunliffe--verizon--net]]
> While we are on the topic, does anyone know what is the browser dependency > for > this? > > onClick="document.location.href=http://somesite.com/somepage.html" >
You my find an answer here: OnClick: http://www.dotcom.ca/index_dot_html/supportkey/a.htm Document.location.href: http://www.dotcom.ca/index_dot_html/supportkey/a.htm This is my new redirect function: http-redir: func [url /local cgi_string row][ print "Content-Type: text/html^/" print rejoin [{<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">} newline {<HTML><HEAD><META HTTP-EQUIV="Refresh" CONTENT="1;URL=} url {"> <SCRIPT> <!-- var version = parseInt(navigator.appVersion) // replace is supported if (version>=4 || window.location.replace) window.location.replace("} url {") else window.location.href = "} url {" // --> </SCRIPT> </HEAD></HTML>} ] ] Will Arp [warp--reboot--ch]

 [20/24] from: jason:cunliffe:verizon at: 24-Oct-2002 10:10


Hi Ed Thanks for such a detailed answer. Q1. How do you know this and is there a particular resource you suggest to verify these issues? Q2. If JavaScript is turned off, can you suggest a strategy to detect/handle that? What do you suppose are the stats on JavaScript disabling? Q3. Is there any way to do the redirect without JavaScript dependency? Q4. Are you saying that the back button triggers the replace() event ?
> Tip: To avoid mangling the functionality of the > browser Back button (due to the redirect), use the
<<quoted lines omitted: 8>>
> </script> > I wish more sites would use this technique.
thanks ./Jason

 [21/24] from: gscottjones:mchsi at: 24-Oct-2002 9:41


From: "Will Arp"
> You my find an answer here: > .. > Document.location.href: > http://www.insidedhtml.com/tips/functions/ts14/page1.asp
Hi, Will, That is a clever trick. Thanks for sharing. --Scott Jones

 [22/24] from: tomc:darkwing:uoregon at: 24-Oct-2002 12:31


it won't work anywhere javascript is turned off ...starting with my browser On Thu, 24 Oct 2002, Jason Cunliffe wrote:

 [23/24] from: hallvard:ystad:helpinhand at: 24-Oct-2002 21:52


Hi Dixit Jason Cunliffe (16.10 24.10.2002):
>Hi Ed >[...] >Q2. If JavaScript is turned off, can you suggest a strategy to detect/handle >that? What do you suppose are the stats on JavaScript disabling? > >Q3. Is there any way to do the redirect without JavaScript dependency?
Sorry if I wasn't clear enough. But if you do a redirect with the HTTP headers, you don't need to worry about JS dependency. All browsers that support HTTP/1.0 will follow redirects for you. (Some might not though, homemade browsers, java browsers that explicitly are told not to...). Check the HTTP protocol specification if you need to: http://www.w3.org/Protocols/. Second thought: do you need to do a redirect _after_ you have finished with the header? If you cannot detect whether or not you shall redirect before the HTTP header is written out, well, then my suggestion fails... ~H

 [24/24] from: tomc:darkwing:uoregon at: 24-Oct-2002 15:46


here a simple redirect from a cgi that does not require much from the client and does not mess with my back button #! /bin/rebol -sqw rebol[] print{Location: http://www.rebol.com } q an instance of this cgi can be found at http://darkwing.uoregon.edu/~tomc/ note the 'q at the end is just to be parinoid. if there are browsers it does not work for I would be interested to know as for not knowing what you are going to write out -- that is what buffers are for. On Thu, 24 Oct 2002, Hallvard Ystad wrote:

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted