# Cgi output problem

**URL:** <https://www.ruby-forum.com/t/cgi-output-problem/61498>\
**Category:** Ruby\
**Created:** [May 24, 2006, 4:32pm UTC](https://www.ruby-forum.com/t/cgi-output-problem/61498 "2006-05-24T16:32:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![javier\_v](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7bcc69/32.png) [@javier\_v](https://www.ruby-forum.com/u/javier_v)\
**Post date:** [May 24, 2006, 4:32pm UTC](https://www.ruby-forum.com/t/cgi-output-problem/61498/1 "2006-05-24T16:32:42Z")

</div>

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](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.

---

<div class="post-metadata">

**Author:** ![javier\_v](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7bcc69/32.png) [@javier\_v](https://www.ruby-forum.com/u/javier_v)\
**Post date:** [May 24, 2006, 7:10pm UTC](https://www.ruby-forum.com/t/cgi-output-problem/61498/2 "2006-05-24T19:10:27Z")

</div>

Javier V. 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](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 W.
