Redirect naked domain to www along with http to https – Google Domains DNS

By Anil Gupta,  13 Jan, 18       0  Tech Tips

Redirect naked domain to www along with http to https using Google Domains DNS synthetic records. Speeds up website. Good for Google SEO. DNS settings cached with 301 redirect. Easy fix.


It may seem tricky or an important question while you are searching an answer to ‘Redirect your naked domain to www sub-domain’.
Also, it would be good if you can do redirect the ‘http‘ version of your website to ‘https‘ version right at the DNS level too.

Many people do these re-directions at web server level using IIS or Apache or Nginx , which incidentally adds a bit of extra time to your website load.

Redirect naked domain to www using synthetic records in Google domains

  1. Go to your Google domains
  2. Click on DNS settings button:

    Google domains DNS settings
    Google domains DNS settings
  3. On the DNS page, delete the ‘A’ record, if you already have any that’s making your naked domain point to your web server:

    Delete A record pointing to IP address
    Delete A record pointing to IP address
  4. Scroll up to the Synthetic records section and add the sub-domain record:
    Forward naked-domain to www by creating a synthetic record
    Forward naked-domain to www by creating a synthetic record
  5. At this time, your basic domain forward to www is set up. The next task is to redirect http version to https, is you are using SSL certificate.
    Click on ‘Edit‘ on the just added synthetic record and change the ‘http‘ in the URL to ‘https‘. Click ‘Save’ and you are all set.
    Redirect http to https in Google domains DNS
    Redirect http to https in Google domains DNS

So, you have achieved two tasks with a single stroke in Google Domains. Isn’t it awesome. You have saved two trips (or two re-directions) that were probably handled currently by your web server and cut off several milliseconds from your website’s page load.

Problem with Google Domain synthetic record

When you set up the above synthetic record, your redirection works fine except if the user tries to reach your site using

https://example.com

Using https in this case will result in NO page found error as google domains cannot check HTTPS at DNS level. It has to be done by web server.

At this time, the only solution that we know works is to get rid of the above mentioned ‘Synthetic record’ trick and use the redirection in web server.
If you are using Apache, this configuration would work:


RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP:X-Forwarded-Proto} =http [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [L,NE,R=301]

Source: https://simonecarletti.com/blog/2016/08/redirect-domain-http-https-www-apache/