Home > Blockchain >  How to redirect Subdomain to domain with same url in Rails
How to redirect Subdomain to domain with same url in Rails

Time:02-21

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

CodePudding user response:

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'.

CodePudding user response:

I found another solution that is.... in routes.rb file

authenticate :user, lambda { |u| u.role == "admin" } do
mount RailsAdmin::Engine => '/admin', as: 'rails_admin'
end

Put this Code Under constraints DomainConstraint do this will access the rails_admin with localhost:3000/admin only, not with example.localhost:3000/admin

  • Related