views:

62

answers:

3

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).

A: 

You need to get your web root to point to /home/mydomain/etc/rails_apps/mysitedir/public/ Maybe this can be configured in cpanel?

If you can get access the shell you would do something like(syntax may vary slightly):

ln -s /home/mydomain/etc/rails_apps/mysitedir/public/ /home/mydomain/public_html

Note that you need to remove public_html first, you should verify that there are no negative consequences of this.

Roger Ertesvag
Would that take care of the problem with routing as well or would it be just for the stuff that's in the rails public folder (javascript, stylesheets, images)?
JRL
Will this command to create a symlink create a file somewhere that I could just directly create on my PC and upload to the website?
JRL
I tried running that command to create a symlink (used a cronjob, no access to shell) and it returned:ln: creating symbolic link `/home/mydomain/public_html/public' to `/home/mydomain/etc/rails_apps/mysite/public/': File exists I suppose that is an error.So what does it mean? And also, in your syntax, why does the first path end with a trailing slash, while the second doesn't? Is that an error?
JRL
I'm on solaris, so you may try to drop the slash depending on the system you are using. Also you probably have to delete public_html, you should check that this has no side effects first.An alternative solution would be to check if cpanel lets you change the web root to point to your applications public directory.
Roger Ertesvag
I have updated the answer to make things a bit clearer
Roger Ertesvag
A: 

The problem is with my web host. Still hasn't been resolved by them.

JRL
A: 

I came across the exact same problem and found a fix. In the .htaccess file, remove that first '$' so you have:

RewriteRule ^/? "http\:\/\/127\.0\.0\.1\:12030%{REQUEST_URI}" [P,QSA,L]

That first bit is a Regex, so the $ matches the end of the URL.

As a side-rant, this is the umpteenth problem I've had to solve today because cPanel sucks.

rogueg