Comments: Removing "public" From the URL of Rails Apps


Great article. Just wondering if your links in your Rails app (using link_to) appear with the public still in? I've tried to adapt your method slightly to also remove /myrailsapp so that / is the start of my rails app.

I've modified all the paths accordingly but I'm now getting links as /myrailsapp/public/blog/show/1, for example and one or two are even linking incorrectly with :id.:format on the end. I guess its a routes.rb issue, but I can't figure it out.

Posted by James Howard at June 22, 2007 05:22 PM

Hi James,

Sorry for the delay in replying, you caught me in the middle of moving country :-)

I've just checked some of the places where links get created in my app (using link_to and image_tag), and neither of them have "public" in the URLs anywhere.

Where are the dispatch.* scripts living in your installation? I think the URLs created by link_to, etc. are all relative to the location of the dispatch script (and /myrailsapp/public is the default location for the dispatch scripts). My guess is that you're redirecting the "/" URL to the "/myrailsapp/public/dispatch.fcgi" rather than "/myrailsapp/dispatch.fcgi". /myrailsapp/dispatch.fcgi doesn't exist on the standard Rails install - I just copied the one from public and changed the line in it where it "require"s the environment so that the new path was correct.



Posted by Adrian at July 11, 2007 10:45 AM

I'm also trying to remove the public part of the URL and have hit some problems. I've set up the rails skeleton in /httpdocs/ and it works fine when going to /public/. I've modified the dispatch.* files and placed them in /httpdocs/ and copied in .htaccess (I haven't done the mod_rewrite changed yet).

However, when I now go to / after a while I get an Error 500 because the rails application couldn't start. I can't see anything in the logs about why.

Any help is appreciated.

Posted by Michael Smith at September 17, 2007 11:43 AM

Do you still get a 500 error if you retry the page straight away?

When you get those sorts of crashes, it usually generates a log in RAILS_ROOT/log/fastcgi.crash.log rather than the usual log file.

I did sometimes get 500 errors because the dispatch.fcgi had given up waiting before rails had had chance to start, but if I reloaded the page straight away rails would have started and the subsequent request would succeed.

That was a separate problem that I ended up having to tweak the dispatch.fcgi to fix.

Posted by Adrian at September 18, 2007 08:20 AM

I know this is an old topic, but I really need your help with this stuff... have set up Passenger now so that Rails runs better with Apache, which is great!

I want to do the same as you have here, but don't know if I can use the dispatch.rb script with Passenger. Would you know if it's possible?

Posted by John Porter at November 23, 2010 07:26 PM
Post a comment

Remember personal info?

Note: I'm running the MT-Keystrokes plugin to filter out spam comments, which unfortunately means you have to have Javascript turned on to be able to comment.