Add multiple Subdomains in Ruby On Rails 7

Subdomains are a great way to organize different parts of your app. You might have an api subdomain, news subdomain, etc.

routes.rb

constraints subdomain: 'my-subdomain' do
  # add routes
end        

development.rb

Add new hosts to your development.rb configuration.

config.hosts << "my-subdomain.my-domain.local"        

Development Environment

Add development subdomain(s) to your /etc/hosts file so it routes to your development server

127.0.0.1 my-subdomain.my-domain.local        

Don’t forget to add port 3000! You’ll go this url in your browser. my-subdomain.my-domain.local:3000

Heroku

DNS Configuration

Add a CNAME record for each subdomain in your DNS configuration.

Use the domain name and DNS Target from Heroku.

That’s it! You should be good to go.

David Raja

Architect @ Persistent System | Ruby on Rails Tech Lead | AWS Certified | PG-AI&ML| Problem-Solving Enthusiast | Transforming Ideas into Scalable Solutions

5 个月

Great post! Adding subdomains is definitely a useful way to organize different parts of an app. Another benefit of using subdomains is that it can improve SEO by making it easier for search engines to understand the structure of your website. Additionally, using subdomains can also help with security by allowing you to isolate different parts of your app and apply different security measures as needed. Thanks for sharing this helpful information!

回复

要查看或添加评论,请登录

Ronak Bhatt的更多文章

  • Rails 6, Stimulus events

    Rails 6, Stimulus events

    An action is a connection between: a controller method the controller’s element a DOM event listener…

    1 条评论
  • Rails 6, Stimulus and Select2

    Rails 6, Stimulus and Select2

    This is just a quicky, to help out anyone using Rails 6, or any Stimulus-enabled Rails project and Select2, the amazing…

    11 条评论

社区洞察

其他会员也浏览了