Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to set up a Rails website on Bluehost and I'm having trouble with the path helpers. As I don't want to monkey-patch Rails, I'm trying to solve this through .htaccess. Here's the scenario:

  1. I'm hosting on public_html/engradado, which points to rails_apps/engradado/public
  2. I'm rewriting to point to, through this public_html/.htaccess file:

    # .htaccess main domain to subdirectory redirect
    # Copy and paste the following code into the .htaccess file
    # in the public_html folder of your hosting account
    # make the changes to the file according to the instructions.
    # Do not change this line.
    RewriteEngine on
    # Change to be your main domain.
    RewriteCond %{HTTP_HOST} ^(www.)?$
    # Change 'subdirectory' to be the directory you will use for your main domain.
    RewriteCond %{REQUEST_URI} !^/engradado/
    # Don't change these line.
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    # Change 'subdirectory' to be the directory you will use for your main domain.
    RewriteRule ^(.*)$ /engradado/$1
    # Change to be your main domain again.
    # Change 'subdirectory' to be the directory you will use for your main domain
    # followed by / then the main file for your site, index.php, index.html, etc.
    RewriteCond %{HTTP_HOST} ^(www.)?$
    RewriteRule ^(/)?$ engradado/ [L]
  3. Here's my rails_apps/engradado/public/.htaccess:

    Options -MultiViews
    PassengerResolveSymlinksInDocumentRoot on
    #Set this to whatever environment you'll be running in
    RailsEnv production
    #RackBaseURI /
    #PassengerAppRoot /home2/engradad/rails_apps/engradado
    RackBaseURI /engradado
    SetEnv GEM_HOME /home2/engradad/ruby/gems
  4. Whenever I call a path helper, e.g. root_url or news_path, it prepends /engradado to the path, so instead of root_url => "" it prints root_url => "", and news_path(1) => "engradado/news/1" instead of news_path(1) => "news/1".

How can I solve this so /engradado isn't prepended to the url?

share|improve this question
If this is pasted from your actual file, you've got a typo on the last line. It says engrandad instead of engrandado. (This won't answer your question, but it may cause other problems if you don't fix it.) – Jenny D Dec 27 '12 at 12:34
That's actually correct. The username is 8 characters long. – Arthur Alkmim Dec 28 '12 at 21:02
Ah, I got confused, thinking that that was the same path that you were reweriting to. Thanks for the clarification. – Jenny D Jan 2 '13 at 9:02

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.