將Redmine架在sub-URI
參考HowTo Install Redmine in a sub-URI及Defect #32318,在config/environment.rb
檔案的最底下加上:
ActionController::Base.relative_url_root = RedmineApp::Application.routes.default_scope
Redmine::Utils::relative_url_root = RedmineApp::Application.routes.default_scope
ENV['RAILS_RELATIVE_URL_ROOT'] = "/redmine"
Redmine::Utils::relative_url_root = ENV['RAILS_RELATIVE_URL_ROOT']
修改redmine目錄下的config.ru
,將:
# This file is used by Rack-based servers to start the application.
require ::File.expand_path('../config/environment', __FILE__)
run Rails.application
改成:
# This file is used by Rack-based servers to start the application.
require ::File.expand_path('../config/environment', __FILE__)
map ENV['RAILS_RELATIVE_URL_ROOT'] || '/' do
run Rails.application
end
參考Bad repository link on search results,在config/additional_environment.rb
加上:
config.relative_url_root = '/redmine'
之後再重啟apache2就可以發現地址由https://127.0.0.1
變成了https://127.0.0.1/redmine
。
注:如果只修改config.ru
,那麼由rails自動生成的超連結仍會指向舊的網址,導致404 error。
以下是試過沒用的方法:HowTo Install Redmine in a sub-URI, Deploying an app to a sub-URI or subdirectory, How to deploy Rails app on subdomain root with Apache and Passenger。
使用此方法後redmine_sidekiq
插件的top menu仍會連結到/sidekiq
而非/redmine/sidekiq
,此問題仍待解決。
undo
config/environment.rb
檔案的ENV['RAILS_RELATIVE_URL_ROOT']
改成:
ENV['RAILS_RELATIVE_URL_ROOT'] = "/"
config/additional_environment.rb
的config.relative_url_root
注釋掉:
# config.relative_url_root = '/redmine'