我正在尝试在 Bluehost 上建立一个 Rails 网站,但在使用路径帮助程序时遇到了问题。由于我不想对 Rails 进行 monkey-patch,因此我尝试通过 .htaccess 来解决这个问题。以下是场景:
- 我正在主持
www.engradado.com
,public_html/engradado
这指向rails_apps/engradado/public
我正在重写以通过此文件
www.engradado.com
指向:www.engradado.com/engradado
public_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]
这是我的
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
- 每当我调用路径助手(例如
root_url
或news_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 前面?