Forum: Ruby Cgi output problem.

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
53a9a7db1aa22b527989ddbf15dd9e34?d=identicon&s=25 Javier Valencia (Guest)
on 2006-05-24 16:32
(Received via mailing list)
I've been using mod_ruby for months and now i have to write a script
that redirects my users to another location.
I use the following:

#!/bin/env ruby

print "Location: http://www......com/index.html\r\n\r\n"


Well, this script doesn't work for me. It just prints as plain text the
Location statement and no redirection is done.
Now, if i change the extension of the script from ".rb" to ".cgi" it
works!

I did a telnet research to my server, and the .cgi returned a 302
status, but the ".rb" returned a 200 OK and two content-type statements,
as if the server is ignoring them or something.

What can i do?
thanks.
10d4acbfdaccb4eee687a428ca00a5d8?d=identicon&s=25 Jim Weirich (weirich)
on 2006-05-24 19:10
Javier Valencia wrote:
> I've been using mod_ruby for months and now i have to write a script
> that redirects my users to another location.
> I use the following:
>
> #!/bin/env ruby
>
> print "Location: http://www......com/index.html\r\n\r\n"
>
>
> Well, this script doesn't work for me. It just prints as plain text the
> Location statement and no redirection is done.
> Now, if i change the extension of the script from ".rb" to ".cgi" it
> works!
>
> I did a telnet research to my server, and the .cgi returned a 302
> status, but the ".rb" returned a 200 OK and two content-type statements,
> as if the server is ignoring them or something.

You need to inform your web-server (apache I assume, since you are
talking about mod_ruby) that .rb files are valid CGI scripts (in
addition to .cgi).  It sounds like it is treating them as data files and
displaying them instead of running them.

Or you can just make all your cgi scripts end in .cgi.

-- Jim Weirich
This topic is locked and can not be replied to.