Heroku - domain redirect. App displayed in a frame - ruby-on-rails

I want to redirect myapp.herokuapp.com to mydomain.com.
What I was able to achieve with company that I bought a domain from (lets call them X) is to add new CNAME, so a www.mydomain.com displays myapp.herokuapp.com and that is OK.
What I also want to do is to be able to access the app without the need to write www before the rest of the address. It was said to me that I should change A record within domain configuration, but X company does not allow it. What I can (and what they recommended) is to set and option in domain configuration called IP/URL/host redirect to myapp.herokuapp.com.
Changing this makes my website available under the mydomain.com without the need to write www before, but what it also does is it displays the website in a frame.
What should I do to achieve this? Is this a heroku thing, the X company thing or should I change something in the way my website can be displayed?
Typing www.mydomain.com displays the website correctly - without the <frameset><frame></frame></frameset> tags.

In the Heroku Dashboard "Domains and Certificate" section, add to your custom domains both domain names, "www.mydomain.com" and "mydomain.com".
Make your DNS target the "mydomain.herokuapp.com" in both records.
Check https://devcenter.heroku.com/articles/custom-domains for more information.

Related

How to keep source URL displayed in redirected address?

I have registered 2 websites (say source.com and target.info) but only one (target.info) is hosted. I could redirect source.com to hosted target.info/source but I would like to display source.com in the address bar rather than the physical URL target.info/source or subdomain source.target.info. Is this possible, knowing that I don’t have a .htaccess for source.com since it is not hosted?
I tried to redirect source.com to target.info/source on my registrar account but then I get target.info/source in the address bar. Ideally I would like to have source.com concatenated with the file names, but source.com alone would be fine.
An alias domain might be close to what you are looking for but you may find it called something different if you use a different hosting provider. You will however, still need to point the domain to your hosting provider (in the case of hosting providers using cPanel whose documentation I have linked this would involve changing the nameservers at your registrar).
Form the docs:
Domain aliases are domains that you own, but which do not contain any content. Instead, they point to the contents of another domain or subdomain on your account. This is useful, for example, to hold a domain that you will later sell, or to redirect traffic to another domain.

URL Redirection and 1and1

I've got an app up and running on Heroku. I've purchased a top level .com domain from 1and1 (I have other sites there, so I thought that would make life easier).
When I attempted to redirect to my Heroku app, I was not allowed to modify the CName alias record like I have done for other sites - which were all subdomains. I was given two options: Frame redirect or HTTP redirect, I've tried both. The frame redirect doesn't seem to function at all - the page stays blank. The HTTP redirect does actually get to my heroku site, but when it displays the address bar shows myproject.herokuapp.com instead of mydomain.com.
I've added both the www.mydomain.com and mydomain.com to my heroku domains.
Is there anyway to add a mask or similar?
Short answer: you can not set CNAME for top of your domain.
Detailed answer: Why can't a CNAME record be used at the apex (aka root) of a domain?
Some DNS providers might offer workaround hacks.

How to make own domain point to specific profile on my app

I currently give the ability for my users to have a subdomain for their account so:
subdomain.myaddress.com
will point to the users profile. I want to be able to give the user the ability to point their own domains as well so that both will work and point to the user profile.
How to do that?
Also, if you happen to know about Heroku. There is a plugin to enable custom domains but I have to call: heroku domains:add *.yourdomain.com (or use GUI)
Is there a way to make my app call that command instead?
Your application will need to listen to whatever domain the user enters, therefore you would have to use the heroku gem inside your application to add the custom domain the user enters to your application.
Using subdomains is obviously the simpler option here as you can just have the wildcard domain setup on your domain *.mydomain.com and let the choose whatever subdomain they want and then have your application work out the account to use from the subdomain.
You can use DNS CNAME records to alias one domain name to another. There are restrictions: you can't use a CNAME on a top-level domain (subdomains only). I don't know about automating it, but CNAME's are commonly used on heroku.

Multiple domains pointing to single Heroku Rails app via nameservers displaying different content?

We have a Rails 3 app which allows users to create a profile and access it with a subdomain. So for example:
user1.app.com
user2.app.com
user3.app.com
Now, suppose they wanted to point their own domain name to their profile, so www.user1.com shows user1.app.com, and www.user1.com/my-content/ shows user1.app.com/my-content/. Is it possible for them to simply change their nameservers to point to us, and we handle the routing? I'm afraid it would be a deal breaker if the user had to do any DNS configuration beyond just changing their nameservers.
Thanks!
This is really two questions.
So I guess I'll answer it like that.
How can I allow customers to add a custom domain to my heroku-based app?
So, in your example, their domain name is www.user1.com
Two things need to happen
www.user1.com needs to be added to your heroku domains for the app
the dns for www.user1.com needs to be set to the heroku servers
In order to add this new domain, I guess you need to store the custom domain in the app,
and when it is changed, or created, ensure a queued task is setup to push this config change to heroku.
In order to do the dns correctly, I hope it is enough that they add a CNAME for user1.app.com.
Therefore, if you have a wildcard CNAME linking to heroku's dns, you can avoid the type of downtime that can occur if Heroku gets DOS-ed again.
How can I show content based on domain, rather than just subdomain?
Well, somehow you already differentiate user1.app.com from user2.app.com
Maybe you just sniffed request.host.
Now you just have to try the custom domain first.
Maybe this'll work.
before_filter :set_client
def set_client
#client = Client.find_by_custom_domain(request.host) || Client.find_by_subdomain(request.host.split(".").first)
unless #client
raise "unrecognised domain #{request.host}"
end
end
You need to get them first of all have them set www.user1.com to point to proxy.heroku.com (or setup your own cname entry to proxy.heroku.com and get them to cname their domains to that) and then you need to register their custom domain with your heroku app so the correct application responds at Heroku stored against their account?? in your application so it can be matched on incoming requests.
This technique is employed in the Locomotive Rails CMS so I'd suggest looking at that - it uses the Heroku gem INSIDE the application so custom domains can be added via the site administrator which in turn talks to the Heroku API to add the custom domain to the application.

SSL-secured website best practices

I have a website (www.mydomain.com) that is secured with an SSL certificate. It is an ASP.NET website and I have forced certain pages via code to be required to use the https:// prefix. If they don't it will redirect them to the https:// equivalent. Is this a good practice? Is there an easier way to do this? Not every single page requires SSL.
Also, when the users use my URL in the form of mydomain.com instead of www.mydomain.com they get a certificate error because the certificate was registered for www.mydomain.com. Should I use the same approach as I am with the http:// and https:// issue I mentioned above? Or is there a better way of handling this?
Your approach sounds fine. In my current project, I force HTTPS when a user goes to my login page, (Based on a config flag which lets me test locally without dealing with needing a cert). This allows me to access other pages unsecured which is handy.
I have a couple places where our server grabs the output of other pages (rendering to html to PDF and fetching dynamic images for example). Because of our environment, our server can't resolve it's public name, so if we were to force ssl at the site we'd have to add, our internal IP address (or fake the domain name).
As for your second question you have two options to handle the www.example.com vs example.com. You can buy a certificate that allows you to have multiple domain names. These are known as UCC certificates.
Your second option is to redirect example.com to www.example.com or the other way around. Redirecting is a great option if want your content to be indexed by google or other search engines. Since they will see www.example.com and example.com as two seperate sites. This means that links to your sites will be split reducing your overall page rank.
You can configure sites in IIS to require a Cert but that would A) generate an error if someone isn't visiting with https and B) require all pages to use https. So, that won't work. You could put a filter on IIS that checks all requests and redirects them as https calls if they are on your encryption list. The obvious drawback here is the need to update your list of pages every time a new page is added (e.g. from an XML file or database) and restart the filter.
I think that you are probably correct in building code into the pages that require https that redirects to an https version if they arrive via http. As far as your cert error goes, you could redirect with a full path (that includes the www) instead of a relative path to fix this problem. If you have any questions about how to detect whether the call uses https OR how to get the full path of the current request please let me know. Both are pretty straightforward but I've got sample code if you need it.
UPDATE - Josh, the certs that handle multiple subdomains are called wildcard certs. The problem is that they are quite a bit more expensive than standard certs.
UPDATE 2: One other thing to consider is to use a Master page or derived class for the pages that need SSL. That way, instead of duplicating the code in each page you can just declare it as type SSLPage (or use the corresponding Master page) and have the Master/Parent class handle the redirect. Again, you'll need to do some URL processing if you take this approach but it is pretty trivial.
Following is something that can help you:
If it is fine to display all your website pages with https:// then you can simply update your code to use https:// and set two bindings in IIS. One is for http and another is for https. In this way, your website can be accessible through any of the protocol.
Your visitors are receiving a name mismatch error because the common name used in your SSL certificate is www.mydomain.com. Namecheap is providing RapidSSL certificates through which you can secure both names under single SSL. You can purchase this SSL for www.mydomain.com and it will automatically secure mydomain.com (i.e. without www).
Another option is you can write a code to redirect your visitors to www.mydomain.com website even if they browse mydomain.com.

Resources