Using rails app as on extension of an existing website - ruby-on-rails

I am trying to use rails app as an extension of my Weebly app.
current domain is hosted by Weebly. I am trying to the following,
I am trying to use the one domain for two different applications(Weebly template website and Rails application)
I thought of two solutions and I don't know if any of them are applicable.
solution
add a subdomain eg. welcomerailsapp.example.com
or
www.example.com/welcomerailsapp
I will be pushing my Rails app to the Heroku server
little guidance would be appreciated
thank you

You can use a CNAME record to do what you want. This would be done at your domain registrar or DNS provider.
Example:
Domain: mydomain.com
CNAME www => yourweeblyhost.com (Weebly app server)
CNAME rails => yourrailsapp.com (Heroku server)
www.mydomain.com would then route to your Weebly app, rails.mydomain.com would route to your Rails app.
This can be done on Weebly via the settings tab under your domain. So all you'd need to do is pick a name for your subdomain, with that as the "name" for the CNAME record and point it to the URL Heroku gives you for your Rails app.
You can also get more complex with it by using wildcards.
So if you only wanted one subdomain (www), for example, to route to the Weebly app; you can configure it as such by creating a CNAME for the www subdomain and pointing it to Weebly as noted above. Then, by using a wildcard (usually * on most providers) as the "name" you can tell the internet that [anyotherthing].mydomain.com should route to the Rails app without having to define each subdomain manually.

Related

If I have a www domain pointed to Wix, can I point a sub-domain to Heroku and how would that affect SSL?

I have my website's www domain pointed to a Wix site, but am looking to point a sub-domain to my Heroku app. The domain was purchased from Yahoo Small Business.
i.e. if www.mysite.com points to Wix, can subdomain.mysite.com point to a heroku app with no issues?
My confusion is because of this line in the Heroku docs:
Root domains must be added in addition to any subdomains.
Will adding the subdomain to Heroku mess up the domain on Wix somehow?
In addition, would Heroku still be able to automatically handle the SSL certificates etc. if I do direct the sub-domain to Heroku?
The quote you reference is in relation to adding root domains. Since you want to point a subdomain at heroku that does not concern you.
The part you are interested in is this part: https://devcenter.heroku.com/articles/custom-domains#add-a-custom-domain-with-a-subdomain
Basically you want to tell heroku you will add a custom subdomain (follow the instructions) then you need to configure your DNS records to add a CNAME (this part gives some examples):
Record Name Target
CNAME www whispering-willow-5678.herokudns.com.
CNAME othersubdomain autumn-sunset-1495.herokudns.com.
CNAME examplesecure example-2121.herokussl.com.
CNAME examplesecure-eu example.herokuapp.com.

Wildcard domains on heroku

How can I use wildcard domain on Heroku? My application is using subdomain.
I followed the Heroku custom domain article and mapped my *.mydomain.com to myapp.herokuapp.com. When I visit dev.mydomain.com it points to heroku app but on Heroku app I cant find the subdomain.
In short I want to use subdomain on heroku, like dev.myapp.herokuapp.com. Any suggestions?
The wildcard setup on Heroku instructs Heroku to point any request for a subdomain of given domain to your application.
But here stops Heroku responsibility. Then your application must be able to handle such requests at application level.
In Rails, you can inspect the request details with the request object in your controller. And you can access the specific subdomain with request.subdomain.
So, for example, if you added *.example.com and someone access foo.example.com, the request object will respond with the following values:
request.host
# => foo.example.com
request.subdomain
# => foo
Now it's your responsibility to use such information in your app according to what you are trying to achieve.

How can you provide an A-name/sub-domain redirect to a Rails app?

I have a rails app with a page at http://mydomain.com/hello.
I would also like to have it mirrored at http://a.usersdomain.com, so that this URL is showing the same app, database, etc.
What I am imagining would be similar to how Tumblr allows you to host a blog at title.tumblr.com and usersdomain.com. Is this possible with a rails app?
You can pretty easily allow users to set up a subdomain on your domain. Just set up a wildcard subdomain with your DNS provider and you can have the rails app do the rest no problem.
So anything.myurl.com will go to your rails app. You can then have a method to get the subdomain and identify the user/site or whatever.
The users having their own domain redirect to the subdomain given can be done as Jason has mentioned in his answer.
You can use a A entry on your DNS management center for the domain. You would point subdomain of a to the IP address of the server that is hosting your rails app. If you do not have a static IP address (like Heroku by default) you can use a CNAME entry and point he subdomain on a to the item listed in the Domains area of the Heroku settings or directly to the current URL like tumblr would. For example on Heroku:
subdomain: a => myapp.herokuapp.com
or tumblr/other hosted url
subdomain a on your domain => title.tumblr.com
or your example:
subdomain a on usersdomain.com => mydomain.com
Hope this helps!

Setting up SSL on heroku with custom domain

I am trying to set up SSL for a custom domain on heroku using the ssl-endpoint addon. My app uses Rails 3.1.0.
Suppose my custom domain is www.example.com. From this question and various other sources, I found that I am supposed to use secure.example.com rather than example.com as the common name when generating the certificate request. I have a few a questions about this:
Do I have to forward users from example.com to secure.example.com (or do anything else with my domain registrar)?
Will users actually see secure.example.com rather than example.com when using ssl?
Will I have to change anything in my actual Rails application or config in order to get this to work?

Redirecting subdomain for static assets on Heroku

I would like myapp.com/blog to redirect to www.myapp.com/blog. I've installed Refraction to do subdomain redirects at the Rack layer. That doesn't work on Heroku for /blog since my files in /blog are static assets. Any fix?
Sounds like you may be making this more difficult than it needs to be.
If you just want myapp.com/something to redirect to www.myapp.com/something, then goto the domain host that is currently handling the myapp.com domain and create a URL redirect record to do just that. This way, the redirect happens at the domain registrar before it even touches your Heroku server (which is how it should be handled).
An example of this would be to create the following records at your domain registrar (i.e. GoDaddy, NameCheap, etc): http://i.imgur.com/FJrMV.png
Those 3 IP addresses point to Heroku's servers. You should have already set up the custom domain add-on within Heroku if indeed you have some site similar to myapp.com and not myapp.heroku.com
Here's an article / video from Heroku that deals with a little bit of this as well: http://devcenter.heroku.com/articles/custom-domains

Resources