Skip to content

request.url does not take relative_url_root into account #24393

@gioele

Description

@gioele

The URL returned by request.url ignores the value of Rails.config.action_controller.relative_url_root.

The documentation of ActionDisplay::HTTP:URL#url says that it "Returns the complete URL used for this request". This is not true for projects that are not mounted under /.

This means that projects that use request.url cannot work unmodified when mounted under other directories with RAILS_RELATIVE_URL_ROOT.

Steps to reproduce

  1. Create a minimal Rails application with the model "Foo".

  2. In app/view/foo/index.html.erb write

    request.url = <%= request.url %>
    relative_url = <%= controller.relative_url_root %>
    
  3. Setup Apache

    RewriteRule      ^/bar(.*)$  http://localhost:4000/$1  [P,L]
    ProxyPassReverse  /bar       http://localhost:4000/
    
  4. Launch the Rails application

    RAILS_RELATIVE_URL_ROOT=/bar bundle exec bin/rails -p 4000
    
  5. Visit http://localhost/bar/foo

Expected behavior

The page should display

request.url = http://localhost/bar/foo
relative_url = /bar

Actual behavior

The page displays

request.url = http://localhost/foo
relative_url = /bar

Please note the missing /bar in request.url.

System configuration

Rails version: 4.2.5

Ruby version: 2.2.3

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions