Is it possible to remove the .herokuapp part of the url in a rails application running on heroku - ruby-on-rails

Hello wonderful world of the stack!
This is my first deployment using Heroku (I am just using their free service at the moment).
I have set up my domain to point to Heroku and renamed my application and everything works fine. the one thing I would like to change however is the format of the final url.
For example, after typing in:
www.example.com
The page loads and the url changes to:
example.herokuapp.com
Is there any way that I can change this behaviour so that the url remains the same?
I have tried using the help pages supplied by Heroku and various searches (usually similar searches to this question title) but I am not sure if I am searching for the correct thing as I seem to only get unrelated results.
Thanks in advance for any light you may be able to shed on this matter

This sound like a problem with your DNS Domain setup rather than heroku. Read about how to configure your domains properly for heroku use here.
It sounds to me as if you are doing some kind of 'web redirection' (custom stuff that each hosting provider offers) with your domain, when you should set CNAME or A Records.
Which provider hosts your domain / where did you 'buy' it?

Related

Heroku - custom domain DNS

I am a complete newbie when it comes to redirecting etc.
I bought a domain (mydomain.co) and I have a heroku app (mydomain.herokuapp.com) (upgrading to paid in the upcoming month). What I want to do is to be able to access the heroku app after entering the domain url and stay o this domain, and not be redirected to mydomain.herokuapp.com.
My settings for the domain look like this (I translated it myself, so there may be some mistakes):
With this settings, I can access my app but it is displayed in a frame, what's more - some of the pages do not work.
What I want to do is to be able to type mydomain.co and display mydomain.herokuapp.com but as regular site, and not inside a frame. What options should I choose?
Another thing is - will I be able to use the domain (which I paid for) and do the redirect if I do not buy a hosting from the company?
PS I added custom domains to my herokuapp and read their [guide], but I still do not understand.3.
Here are also my domain records - I believe it has something to do with this, but it so hard to test it as those DNS changes take some time.
You should remove your redirection. You also need to put a CNAME on mydomain.co with value mydomain.herokuapp.com.

Want to create staging subdomain e.g staging.example.com

I have e.g www.example.com as my website domain, and now as testing instance I want to add www.staging.example.com. How this can be achieved. I tried searching for solutions on google, but got confused. Any suggestions on this will be greatly appreciated.
Your first line of attack would be to create a new DNS record for the domain you want. This can usually be done from the control panel provided by the service/company you purchased the domain through.
If your staging server is hosted and available at the ip A.B.C.D for example, you'd create a new A record for www.staging that points to A.B.C.D
Once this is done, you'll want to add a new (v)host entry on your server that's housing the staging site (this differs whether you're using Apache, NGINX etc). A simple Google search on how to do this should suffice.

How to point a domain at a heroku application

While I've done this on my VPS, I've never done this for a heroku application, and now I have to do it for a fairly large company so I really want a simple list of bullet-points in how to do this.
I've read these instructions, and I'm still a little bit unclear on what exactly they mean. Again, if I had more time I'd buy some rubbishy domain and test it myself, but I don't have time on my side and need to get this right first time!
Thankfully, no SSL is required at this time.
Here's what I can gather I need to do to point the url www.foobaryfoobs.com at my application, running at warm-chamber-1882.herokuapp.com. Please correct me:
1) I add www.foobaryfoobs.com to the local repository containing the application.
I presume I do this by navigating to the repository on my local machine and running:
$ heroku domains:add www.foobaryfoobs.com
How does this work? Does it update some configuration file somewhere that I need to add to the repository and then push up to heroku?
Are there any caveats or best practices here? What other domains should I add? heroku domains:add *.foobaryfoobs.com, for example?
Heroku advises we use the above wildcard domain here. Why?
2) Log into the registrar that created www.foobaryfoobs.com and navigate to its control panel.
3) Update the domain's CNAME record to point at warm-chamber-1882.herokuapp.com
Am I done for the most part? Now do I just wait?
Is there no IP related stuff?
The domain has several dozen emails attached to it. As long as I don't touch the MX record, I should be fine?
What's a root domain? Why should I add it?
Why should I care that:
Some DNS hosts provide a way to get CNAME-like functionality at the
zone apex using a custom record type.
4) Update the domain's FORWARD / URL record so that foobaryfoobs.com points to www.foobaryfoobs.com
For a nooby, please explain why this is necessary.
3 Conclusive Questions:
1) Is this how it should be set up?:
The app:
warm-chamber-1882.herokuapp.com
Should have the following configurations (saved in some weird config file that I wouldn't mind knowing more about about):
domains:
www.foobaryfoobs.com
*.foobaryfoobs.com
The domain:
www.foobaryfoobs.com
Should have the following records:
CNAME: warm-chamber-1882.herokuapp.com
URL / FORWARD: foobaryfoobs.com target: www.foobaryfoobs.com
MX: *as long as I don't touch them the emails will still work*
2) Am I covered against:
It’s important to make sure your DNS configuration agrees with the
custom domains you’ve added to Heroku. In particular, if you have
configured your DNS for *.example.com to point to
example.herokuapp.com, be sure you also run heroku domains:add
*.example.com. Otherwise, a malicious person could add baddomain.example.com to their Heroku app and receive traffic intended
for your application.
3) How should I adjust the steps for a site that has an SSL backend section?
A.
$ heroku domains:add www.foobaryfoobs.com
How does this work? Does it update some configuration file somewhere that I need to add to the repository and then push up to heroku?
I dont know exactly how does it works internally but this command is equivalent of adding ServerName in apache config file, without this when request comes to www.foobaryfoobs.com it will be forwarded to heroku because of dns but heroku fail to determine your app. You will see the below image.
That's why they need your domain so they know which apps belongs to which domains. They also need it for domain precedence purpose. No changes are required in your code as long as you are okay to allow your user to access Heroku subdomain ie warm-chamber-1882.herokuapp.com. If you dont want user to access heroku subdomain you have to pass 301 http status so it will be redirected to your actual domain i.e www.foobaryfoobs.com . For this you have add this in your application controller
before_action :forward_to_domain_if_heroku_subdomain
private
def forward_to_domain_if_heroku_subdomain
if request.host == 'warm-chamber-1882.herokuapp.com'
redirect_to "http://www.foobaryfoobs.com" , status: 301
end
end
Are there any caveats or best practices here? What other domains should I add? heroku domains:add *.foobaryfoobs.com, for example?
if you ONLY want to use www.foobaryfoobs.com as your domain, this command is suffice ie
heroku domains:add www.foobaryfoobs.com
If you want to assign naked domain foobaryfoobs.com then you ALSO have to run
heroku domains:add foobaryfoobs.com
If you application use subdomains like subdomain.foobaryfoobs.com then you also have to run
heroku domains:add foobaryfoobs.com
2) Log into the registrar that created www.foobaryfoobs.com and navigate to its control panel.
To be precious, you have to do DNS management tool.
3) Update the domain's CNAME record to point at warm-chamber-1882.herokuapp.com
Yes.
Am I done for the most part? Now do I just wait?
Yes, but there are also other things.
Is there no IP related stuff?
Yes, there is no ip related stuff.
The domain has several dozen emails attached to it. As long as I don't touch the MX record, I should be fine?
Yes.
What's a root domain? Why should I add it?
if you want to accept requests from user at warm-chamber-1882.herokuapp.com (not www. warm-chamber-1882.herokuapp.com) then you have to add it.
Why should I care that:
Some DNS hosts provide a way to get CNAME-like functionality at the zone apex using a custom record type.
Yes. They are talking about ALIAS or ANAME type of records. (DNSimple provides it). You have to care it because from that custom-record-type it is easily to add record. They are like pre defined templates eg ALIAS is template of A record.
4) Update the domain's FORWARD / URL record so that foobaryfoobs.com points to www.foobaryfoobs.com
For a nooby, please explain why this is necessary.
It is necessary because www.foobaryfoobs.com and foobaryfoobs.com are different in a same way like images.google.com and news.google differs. www is nothing special it is just a subdomain. If you dont do this, user can't use your site from foobaryfoobs.com but can access www.foobaryfoobs.com.
B.
1) Is this how it should be set up?
Yes, it is correct. But if you want to allow foobaryfoobs.com and www.foobaryfoobs.com, you have to do something like below table. You dont require *.foobaryfoobs.com record if your app doesn't use any subdomain except www. It is bad practice actually to add *.foobaryfoobs.com .
Type | Name | Content
---------------------------------------
ALIAS | foobaryfoobs.com | yoursite.herokuapp.com
CNAME | www.foobaryfoobs.com | yoursite.herokuapp.com
It’s important to make sure your DNS configuration agrees with the custom domains you’ve added to Heroku. In particular, if you have configured your DNS for *.example.com to point to example.herokuapp.com, be sure you also run heroku domains:add *.example.com. Otherwise, a malicious person could add baddomain.example.com to their Heroku app and receive traffic intended for your application.
Yes. Moreover you dont have to worry about this. If the malicious user can set subdomain at your domain then he capable to do much destruction :P. Actually, malicious user can't access your DNS management tool so you're safe.
In your registrars host records you want to set the # to the redirect to the www.foobaryfoobs.com and the www record to the CNAME of warm-chamber-1882.herokuapp.com, this is because Heroku may change the IP address associated with that hostname and if you have the ip in your registrar you would also have to update. Using a CNAME ties that url to the ip so when Heroku updates the ip your site is still up. As long as you don't touch your MX records your email will be fine.
To protect again *.foobaryfoobs.com issues they warn about you can also setup a host record for exactly that and make it a CNAME as well pointing at warm-chamber-1882.herokuapp.com.
As far as setting up the SSL you can look at this article, that should get you setup.
I can answer only some of this:
1) a) It updates some config stored on heroku's end related to your app. You can see that if you login to the heroku site and look at the config for your app.
b) dunno
c) this will let people type both "http://www.foobaryfoobs.com" and "http://foobaryfoobs.com" and for both of them to go to your app.
You can also do this with an A/AAAA record.. in my opinion the better way.
Check out my answer in this thread
Heroku EU region how to setup custom domain name?

Adding binding hostname in IIS to website breaks site

I'm baffled by an issue with my site in IIS 7 - it works fine when it's the only site that's running, and no binding is being used. I have my domain name www.mysite.com registered with the DNS to point to my IP and it pulls up my site great. However, now I want to add a second site in IIS, so I have to start using the binding host names, but when I put www.mysite.com in as the host name, suddenly I can't pull up the site anymore! And, I don't know if this information is helpful, but if I start up the Default Web Site (that has no bindings) along side my current website that I've added the binding to, the domain name will pull the default web site (IIS7 jpeg) instead! It's like it completely doesn't see the binding I've added, other than the fact that it allows me to run both sites at the same time. It doesn't take time for the binding to take effect in IIS right? Waiting until tomorrow won't make a difference I imagine?
I've done this many times before on other servers, and as far as I can remember, I seem to be doing everything the same as before. I can't figure out why it's not working this time. Am I forgetting something crucial here?
The only difference I can tell is that this domain is hosted with Google, which requires me to update the DNS myself. All those other times, I've called up goDaddy and said, 'Hey, can you point this domain to this IP address?' and they do it for me. Is it possible that I've updated the DNS incorrectly, or incompletely? I don't know if that can be the case if the domain has been pulling up the website just fine all this time until I tried to add the second website on the server... Any ideas?
BTW, this is a virtual server (2008 R2) hosted at atlantic.net - I've never used them before. All the other virtual servers I've used have been with 1and1. Don't know if that makes a difference too.
Ok, I figured it out - turns out the DNS WAS set incorrectly after all! I was able to narrow down the issue when I started creating a bunch of dummy sites and playing with my local computer's hostfile and saw that everything seemed to be routing just fine. So, clearly IIS was working as expected. So, I then called GoDaddy repeatedly until I found someone who agreed to help me with a Google domain. Apparently, from what I could understand, I set the IP address in the wrong place which only made the domain forward as the IP address, so there was no hostname for IIS to match it to, which is why it pulled up the default website (no bindings) with no problems, and ONLY the default website! He directed me to another screen (the DNS Zone File tab) where I could set it properly. Now, everything goes to the expected sites!
Hopefully this will help another newbie out one day when they have to set their own DNS (gasp!)

Subdomains and locally installed Rails app

I can't figure out what I'm overlooking, perhaps it's obvious or lack of understanding.
The app I'm working with uses subdomains which on the hosting server work properly. I figured locally installing would kick up some issues around routing, so I read up on making changes to /etc/hosts and using the Ghost gem. Both seem to work fine i.e. localhost:3000/ becomes myapp.local:3000 but I don't understand how to go about logging into a subdomain account. Here's an example...
myapp.local:3000/session/new = the default login page for the app
myapp.local:3000/signup = default signup page
I can create an account here e.g. Sub1
The thank you page is shown w/ the reference to sub1.myapp.com which points to the hosted app (the local db shows this domain as well)
sub1.myapp.local manually added to /etc/hosts and dscacheutil -flushcache
sub1.myapp.local:3000/session/new is the subdomain
login attempts return that this isn't a valid domain. This seems to make sense because the local db shows the url as sub1.myapp.com on the hosting server.
So my question is whether there's a local workaround that I can use for development or have I totally missed a fundamental concept along the way?
you might just want to try putting the actual dot com in your /etc/hosts file.
ie:
127.0.0.1 sub1.myapp.com
127.0.0.1 myapp.com
127.0.0.1 anyothersubdomains.myapp.com
what this usually does is trick your computer into thinking it is the host of all of those, so you can't go to the real site anymore in a web browser.
if you do want it to be .local, presumably so that you can refer to the real online site while working on a local copy, you should probably take a look in app/controllers/application_controller.rb (sometimes application.rb) and look for logic in there that helps determine what to do depending on the subdomain. maybe its hard coded to only look for a .com or something.
If you are using the webrick server or something like Puma for development you can use lvh.me to access your subdomains. e.g.
http://sub.lvh.me:3000/
http://lvh.me:3000/ is equal http://localhost:3000/

Resources