URL 重写和 Rack 基本路径

URL 重写和 Rack 基本路径

我正在尝试在 Bluehost 上建立一个 Rails 网站,但在使用路径帮助程序时遇到了问题。由于我不想对 Rails 进行 monkey-patch,因此我尝试通过 .htaccess 来解决这个问题。以下是场景:

  1. 我正在主持www.engradado.compublic_html/engradado这指向rails_apps/engradado/public
  2. 我正在重写以通过此文件www.engradado.com指向:www.engradado.com/engradadopublic_html/.htaccess

    # BlueHost.com
    # .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 example.com to be your main domain.
    RewriteCond %{HTTP_HOST} ^(www.)?engradado.com$
    # 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 example.com 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.)?engradado.com$
    RewriteRule ^(/)?$ engradado/ [L]
    
  3. 这是我的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. 每当我调用路径助手(例如root_urlnews_path)时,它都会添加/engradado到路径前面,因此root_url => "http://www.engradado.com/"它会打印而不是root_url => "http://www.engradado.com/engradado/",并且news_path(1) => "engradado/news/1"而不是news_path(1) => "news/1"

我该如何解决这个问题,以便/engradado不将其添加到 URL 前面?

相关内容