• Shirt Designer
  • RS Industrial Services
  • Annoying Boxes
  • Drag Me
  • Bunny Kill
  • Alpha Circulation

Railsapp on your main domain?

rudionrails on June 19th, 2007

The common way to deploy a Rails application is to create a subdomain and point it to the folder where your application lies. This works well for those subdomains as well as addon-domains, but what about your main domain? If you are someone like me who bought the hosting solution together with the domain, then you might wonder how you get your Rails app accessed under this domain.

This site is hosted on Bluehost and there is no facility to point the domain to a specific folder via a control panel. Therefore, there general sequence is as the following:
  1. Create your Rails structure with rails myrailsapp
  2. Create a new subdomain myrailsapp in your control panel
  3. Go to public_html and delete the myrailsapp folder
  4. Make a symbolic link to the folder of the rails app with ln -s ~/path/to/myrailsapp/public myrailsapp
  5. Change your .htaccess in the public folder to get the redirect to the symbolic link

On the verge of getting this web site running I noticed, that all the links are still redirected to http://domain.com/myrailsapp/ instead of remaining at http://domain.com/. All would work, but that’s not what I wanted.

Therefore, I reached for a rather drastic approach: link the public_html/ directly to the myrailsapp/public/ folder:
  1. Create your Rails structure with rails myrailsapp
  2. Rename your current public_html folder with mv public_html public_html-backup
  3. Make a symbolic link to the folder of the rails app with ln -s ~/path/to/myrailsapp/public public_html

This all works pretty well for me. The only thing to mind is copying the subdomains/folders/files that are now in the old public_html-backup over to the new one. Since the new public_html is only a symbolic link to the rails app, it was actually copied into myrailsapp/public/. However, everything works as before.

Now, if you smite your forehead and say: “there’s a much better way”, then please let me know!