rubyruby-on-rails-5rails-admin

How to redirect Subdomain to domain with same url in Rails


I have installed a gem rails_admin in my application now i want to redirect this url eritheia-labs.localhost:3000/admin/dashboard to localhost:3000/admin/dashboard

i wanna access rails admin via localhost:3000/admin instead of eritheia-labs.localhost:3000/admin or if enter this url it will redirect me to localhost:3000/admin


Solution

  • You could add the following to your config/routes.rb

    constraints(host: "eritheia-labs.localhost") do
      match '/admin/(*path)' => redirect { |params, req|
        "http://localhost:3000#{req.fullpath}"
      }, via: [:get, :head]
    end
    

    and make sure it is before the mount RailsAdmin::Engine line.

    This code should redirect any requests for 'http://eritheia-labs.localhost:3000/admin/*path' to 'http://localhost:3000/admin/*path'.