Edit:
Well maybe this can give a clue. When created a Rails app in cPanel on my web host, in order to access the app you need to create a rewrite rule. Which I did, but didn't know what it did. I tracked it down to it creating the following 2 files:
home/mydomain/public_html/.htaccess
:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mydomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.mydomain.com$
RewriteRule ^/?$ "http\:\/\/127\.0\.0\.1\:12030%{REQUEST_URI}" [P,QSA,L]
and
home/mydomain/.cpanel/ruby-on-rails-rewrites.db:
appname: helloworld
domain: mydomain.com
port: 12030
rewritebasepath: /home/mydomain/public_html
url:
It seems that the root URL gets sent to Rails, but any other URL does not and I get an Apache 404 (not a Rails 404). Is there something wrong in the .htaccess file? Is the rewrite condition only for the domain root? If it is, how can I make it for any URL ?
Original post:
I'm trying to deploy a rails website that works fine locally but not on the web server. The rails app starts fine and I can access the home page. But any other link results in a 404.
My home page is set from within routes.rb
like so:
map.root :controller => "home"
I am using RESTful routes and it works fine locally. In routes.rb
all I have is a bunch of
map.resources :posts
map.resources :images
...
If I change the map.root
to another controller (i.e map.root :controller => "posts"
, then that single page will display fine as well, and all other links will return 404s, including the one that previously worked when it was the one referenced in map.root
.
This is my first rails deployment so it might be me doing something wrong. My web host tech support told me it's a coding issue and that they can't help me.
My website directory structure online is like so:
/home/mydomain/etc/rails_apps/mysitedir/ <- rails folders (app, config, db, ...)
/home/mydomain/public_html/ <- nothing here
Also, the files that are in my rails public folder, do they need to stay in that folder or should they be put in the public_html
folder on the web? Because right now they're not found either. If I put them in the public_html
folder though, they are found from the home page (javascript and css and images).
In my error log in cPanel, it shows errors like:
[Mon Oct 05 08:19:41 2009] [error] [client XX.XX.XX.XX]
File does not exist: /home/mydomain/public_html/market,
referer: http://www.mydomain.com/
Where market is one of the links I'm trying to access from my home page, for example, and it's one of my controllers.
In short, the only location I can access is the root.
What am I doing wrong that I am getting all these 404s? I do not have shell access, all I have is cPanel. This is with Ruby 1.8.5 and Rails 2.3.4, the (shared) web server is Linux + Apache 2.2.11 (Unix).