Search code examples
ruby-on-railsroutesruby-on-rails-5passenger

How does rails know if it runs under a subpath?


I want to run a rails app on https://server.com/myapp/testing. If I say redirect_to '/bla', I want it to redirect to /myapp/testing/bla. How do I tell rails, that it should prefix all paths with /myapp/testing?

I'running rails 5 and passenger with apache httpd.


Solution

  • As it is said here in the docs, you can config your rails app to run in a subdirectory by adding this line in config/application.rb

    config.relative_url_root = '/myapp/testing'
    

    This will help rails to generate the appropriate routes.

    You may also need to config your passenger config according to this docs

    Edit: As suggested by @le_me, RAILS_RELATIVE_URL_ROOT must be set for passenger to communicate the prefix to the rails app.