Resources:
Categories:
Give us your email and we'll send you the good stuff.
Categories:
When it comes to DNS, there's nothing we love more - except DNS management. And maybe Secondary DNS. Or Failover. Even anomaly detection. Oh who are we kidding, if it's even remotely close to the topic of DNS, we got you covered!
No matter the case. If you have ever considered setting up your redirects at the DNS level… this article will answer every question you could ever have.
No, you cannot redirect HTTP to HTTPS at the DNS level. This is something you have to configure on your web server (because it manages the protocol). If you don't have access to your web server, you will need to contact your web hosting provider.
Redirects that you CAN do with DNS, as well as an introduction to HTTP/HTTPS redirections...
A redirect is an HTTP response with a 301 status code and the new location. It looks something like this:
>>> http://constellix.com
> --------------------------------------------
> 301 Moved Permanently
> --------------------------------------------
Status: 301 Moved Permanently
Code: 301
Server: nginx/1.10.3 (Ubuntu)
Date: Wed, 01 Aug 2018 22:11:33 GMT
Content-Type: text/html
Content-Length: 194
Connection: close
Location: https://constellix.com/
Redirects are commonly used to tell website visitors and search engines which URL is the one you want them to see. In this case, we want our users to only visit the HTTPS version of our website. The 301 simply tells users that https://constellix.com is the intended destination for our website.
Since HTTPS is now a standard for all websites, it’s become more important than ever to redirect traffic to the HTTPS version of a website. Recently, browsers like Google Chrome are showing “nonsecure” badges for websites still running over HTTP.
Keep in mind that for a lot of the examples in this article, there is more than one way to create the redirect. Like in the previous example, you can set up a redirect on your web server to automatically send all traffic to the HTTPS version of the site, no matter what page they are visiting. You can also do it at the DNS level using an HTTP redirection record (we’ll talk more about this in a minute).
There are other kinds of “redirects” at the DNS level, but they don’t operate over HTTP or HTTPS protocols. Instead, they are records that point one hostname or IP to another.
How about when www. disappeared from the beginning of URL’s? All it takes is a simple CNAME record and you can redirect all traffic hitting www. to go to the “naked” version of your domain, like example.com.
Go ahead and try it! Prepend www. to an address and see where you end up.
>>> https://www.constellix.com
> --------------------------------------------
> 301 Moved Permanently
> --------------------------------------------
Status: 301 Moved Permanently
Code: 301
Server: nginx/1.10.3 (Ubuntu)
Date: Thu, 02 Aug 2018 17:56:53 GMT
Content-Type: text/html
Content-Length: 194
Connection: close
Location: https://constellix.com/
You can also test for redirects to HTTPS by prepending http:// to a URL.
So how are regular DNS records like A and CNAME different from HTTP redirects?
DNS records are confined to redirects within the same FQDN (Fully Qualified Domain Name) or zone.
I own www.mydomain.com and I want to point it to blog.mydomain.com. I CAN do that with a CNAME record.
Okay, but what if I own mydomain.com and I want to redirect it to myfriendsdomain.com? I would have to use an HTTP redirect since the second hostname is not one in my current zone.
HTTP redirects operate very differently from traditional DNS records. That’s because they require the help of a dedicated web server to store all of the redirects.
When you create an HTTP redirection record, you’re actually making an A record that points to that web server. The web server will respond with a 301 redirect and the destination URL.
But this is only one step in the lookup process. To better understand how HTTP redirects work, we need to go back to the very beginning.
When you enter a website into your browser, what happens?
What does this have to do with redirection? Everything. If you are querying a domain that isn’t secure (over HTTP) but it redirects to a secure domain (HTTPS) the handshake will never take place.
That’s because web servers that host secured domains also have to be secure.
Both domains in a redirect must have SSL certs. That means you can’t redirect an HTTPS site to an unsecured one.
A lot of SysAdmins run into this kind of issue, and there are a few reasons why.
In most cases, you may not have purchased an SSL certificate (allows you to run over HTTPS), but if you use a CDN your website could still be running over HTTPS. That’s because most CDN services will automatically create an SSL certificate for your domain when you add your domain to their network.
Let’s go back to what happens when you enter a website into a browser, but this time the website we are looking for uses HTTPS.
Now when a redirect happens, we still go through the first two steps. However, the server will respond with the redirect code and location over a secure connection.
Bottom line. If you want to redirect a secure hostname to anything (secure or not)... then you must have a valid SSL certificate on the web server that the hostname is hosted. Otherwise, you’ll fail at step one.
Okay, now that we have all of that out of the way. What kinds of HTTP/HTTPS redirects can you do with DNS?
Exactly what it says. This is the standard for most redirects.
Tells search engines that you may change it later, so they should check again.
This kind of redirect actually creates a “framed” experience in the browser. The user will see the original URL in their browser but will see the content from the destination URL.
You can also configure a hidden frame redirect to not include the path the user entered into their browser.
For example:
Say a user enters www.domain.com/my-blog into their browser
You have a hidden frame redirect set up that will show the original URL in their browser, but show the content for www.notmydomain.com.
A hard link will remove the path “my-blog” from the end of the URL and not append it to www.notmydomain.com.
You also have the option to configure the meta tags for the framed page.
Remember, don't try to use an HTTP redirection record to redirect HTTP to HTTPS. Only use HTTP redirection records to point an FQDN to another FQDN.
Sign up for news and offers from Constellix and DNS Made Easy