Forum: Rails deployment rails rewrites URL by appending "dispatch.cgi" to URL

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.
Augusto C. (Guest)
on 2009-05-05 19:07
hi-

i have a rails running on a server, but when i access my site as:

 "http://test.com"

it rewrites the URL with the name of the dispatch.cgi script:

  "http://test.comdispatch.cgi%2Flist_topics"

which then fails to resolve.

i'm using the standard .htaccess file and dispatch.cgi file.

any ideas?

thanks,
augusto.

.htaccess
===
Options +FollowSymLinks +ExecCGI
AddHandler cgi-script .cgi
RewriteEngine On
RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ dispatch.cgi [QSA,L]
ErrorDocument 500 "<h2>Application error</h2>Rails application failed to
start properly"
===

dispatch.cgi
===
#!/usr/bin/ruby
require File.dirname(__FILE__) + "/../config/environment" unless
defined?(RAILS_ROOT)
require "dispatcher"
ADDITIONAL_LOAD_PATHS.reverse.each { |dir| $:.unshift(dir) if
File.directory?(dir) } if defined?(Apache::RubyRun)
Dispatcher.dispatch
===

routes.rb
===
ActionController::Routing::Routes.draw do |map|
  map.connect ':action/:id',
              :controller=>'board'
end
===

board_controller.rb
===
class BoardController < ApplicationController
  def index
    redirect_to :action=>'list_topics'
  end
===
Vamsi krishna K. (Guest)
on 2009-07-07 15:33
Augusto,

Can you try the below .htaccess and see if that helps.


CGI
==
AddHandler fastcgi-script .fcgi
AddHandler cgi-script .cgi
Options +FollowSymLinks +ExecCGI
RewriteEngine On

RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ dispatch.cgi [QSA,L]

ErrorDocument 500 "<h2>Application error</h2>Rails application failed to
start properly"
==

FCGI
==
AddHandler cgi-script .cgi
Options +FollowSymLinks +ExecCGI
RewriteEngine On

RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]

ErrorDocument 500 "<h2>Application error</h2>Rails application failed to
start properly"
==

Thanks,
Kilari.
http://kilari.co.in

Augusto Callejas wrote:
> hi-
>
> i have a rails running on a server, but when i access my site as:
>
>  "http://test.com"
>
> it rewrites the URL with the name of the dispatch.cgi script:
>
>   "http://test.comdispatch.cgi%2Flist_topics"
>
> which then fails to resolve.
>
> i'm using the standard .htaccess file and dispatch.cgi file.
>
> any ideas?
>
> thanks,
> augusto.
>
> .htaccess
> ===
> Options +FollowSymLinks +ExecCGI
> AddHandler cgi-script .cgi
> RewriteEngine On
> RewriteRule ^$ index.html [QSA]
> RewriteRule ^([^.]+)$ $1.html [QSA]
> RewriteCond %{REQUEST_FILENAME} !-f
> RewriteRule ^(.*)$ dispatch.cgi [QSA,L]
> ErrorDocument 500 "<h2>Application error</h2>Rails application failed to
> start properly"
> ===
>
> dispatch.cgi
> ===
> #!/usr/bin/ruby
> require File.dirname(__FILE__) + "/../config/environment" unless
> defined?(RAILS_ROOT)
> require "dispatcher"
> ADDITIONAL_LOAD_PATHS.reverse.each { |dir| $:.unshift(dir) if
> File.directory?(dir) } if defined?(Apache::RubyRun)
> Dispatcher.dispatch
> ===
>
> routes.rb
> ===
> ActionController::Routing::Routes.draw do |map|
>   map.connect ':action/:id',
>               :controller=>'board'
> end
> ===
>
> board_controller.rb
> ===
> class BoardController < ApplicationController
>   def index
>     redirect_to :action=>'list_topics'
>   end
> ===
This topic is locked and can not be replied to.