purplesSaga

February 1, 2023

Root Domain Redirection

It’s a repeating topic that you can have tons of information around the world. However, it just happened to my working place that create many “discussions”. Not an interesting topic.

This page: How to Redirect from Your Root Domain to the WWW Subdomain and Vice Versa Using mod_rewrite explained why you wish to do so and the traditional way of doing so when you host your Web site under apache. This page: Back to Basic: DNS ALIAS records briefly explain why many people would say you cannot do so in DNS.

TL;DR

  1. You want to do so mainly due to search engine, or say in a more modern wording: SEO (search engine optimization).
  2. Traditionally, DNS won’t allow you to set the root domain with CNAME because, by the specification, you cannot specify another DNS entry of any type once you’ve define it as CNAME. The root domain, specify by “@“, normally, is used for MX or SOA and it would violate the rule.

Traditional Workaround

The situation is simple when you have your only Apache hosting your Web site. Just add a .htaccess entry as specified in the like above. This comes fishy when you have an CDN / external Web hosting / CMS hosting internally or externally without an explicit Web server to make such configuration. However, you can always set an individual Apache (ok, you can do the same with NGINX) to do the same traditional 301 redirect by pointing your root domain to the IP of the Apache using A record.

Set on the DNS Services

If your DNS server support domain ALIAS, you can easily set the root domain entry to ALIAS to www of your domain (see the link about). The argument I face here is… Hey, your named won’t support this and please don’t set the CNAME for the rule domain, genius.

My bad and update here. Both CNAME and ALIAS in DNS is not a good option in concern of SEO:
CNAME vs 301 Redirect
ALIAS vs 301 Redirect

In short, both will result in serving your root domain with your content in the destination, but under the root domain. You will need a proper 301 Redirect to notify the search engine that your root domain is actually moved to WWW. I assume when you reading this, you know why you need to do so (but I believe many traditional IT staff won’t though,) so I won’t explain it in details here. Likely if you are reading this, actually it’s your marketing or corporate communication staff catching your IT to do that and they can’t explain clearly the technical differences…. 😀

Modern DNS, for example AWS Route 53, Google Domain and CloudFlare DNS. I don’t detail their documentation here for their proprietary implementation. Something unfortunate to Azure DNS users that the alias handling only apply to Azure CDN endpoint (to this point of time). You may need to seek alternative.

Set on the F5 BigIP

Oh yes, if your site have F5 BigIP as on-premises load balancer, it will be more sensible to do a redirect with iRules without setting an extra Web server setup. Go google their documents and I’m sure it is listed in the FAQ.

Some CMS / CDN Setup

Some CMS / CDN hosting may support this, check with your vendor.

Afterword

Anyway. I’m using Google Domain in this Web site. So I have already done a simple Domain Redirect to serve the purpose. (Not an advertisement.)

Simple life…. 😀

Read More
January 17, 2023

Static Content Publishing in S3

Just a summary of google works. This is my original work of the cicd-demo of mine solving my concern of hosting my website at minimal cost and effort without a ”server”.

Web site on S3

Actually, you don’t need things in AWS like Cloudfront or Route 53, S3 is capable to release content as a Web page: Look for Static website hosting under Properties in your S3 bucket.

Enable it and edit the stuff for your liking. You will have a web address to your S3 bucket for static hosting. Just a note that your S3 bucket will be readable to public as a result.

Too simple, right. Minimising the cost is very simple with your free tier in AWS. To me, I want to explore for a rather complete end-to-end publishing from CMS (e.g. WordPress), to deploy static content with CICD under AWS because I got too bored with Azure… 😀

CICD with CodePipeline from GitHub

One of the choice for versioning could be CodeCommit for solely AWS solution. You may save a bit step as me with CodeCommit and CodePipeline, as long as you can work with the IAM policies (simple anyway). Just a matter of personal choice, I use GitHub instead. Sithum has made a very good guide to do so. I’d rather not repeat here. Just add a note from his guide that instead of GitHub, you can select CodeCommit from the source for a complete AWS suit implementation.

Besides, I have made a simple step to remove .gitignore from the automatic publishing to S3 before the deployment.

First, you need to create a Build project under CodeBuild, say, RemoveGitIgnore

Insert the build command:

version: 0.2

phases:
  build:
    commands:
      - find . -name ".gitignore" -type f -delete
artifacts:
  files:
    - '**/*'

Add a stage in your pipeline after the Source before the Deploy, say, Remove Dummies.

Then you will be good on next run.

CloudFront and DNS

I won’t include much related to the DNS setup for custom domain. It’s rather depends on your need and preference of registrant. The action I took considering to avoid making the S3 bucket public, so I linked the S3 bucket with CloudFront for content distribution.

To start with, create a Distribution under CloudFront. You will have options to select your current S3 buckets. Find the one associated with your website. Note again, you don’t need to make your S3 bucket public.

Other items will be a matter of choice (or cost) like: alternative domains, cache scope, and SSL.

If you are curious like me, you may set and alternative domain to setup the CNAME in your DNS setting forwarding to the Cloudfront domain available after creation, and request a AWS managed certificate (free!) for your website.

This covers the basic.

With a further search on the WordPress integration with the flow mentioned about, I noted that there is a WordPress plugin to generate a static website. Thinking if it can be done by using LightSail injecting the git command to GitHub, but I stop here and rested for 4 months… 😀

Afterword

After setting the WordPress in LightSail, honestly I changed my mind. It’s rather easy and inexpensive to setup a WordPress site with LightSail, even with backup and CDN. What the demo-cicd would apply when you wish to have a rather static website with a protected content management server within your premises. Whether you need a GitHub for versioning and staging could be a sign issue.

Anyway, fun to play. 🙂

Read More
September 19, 2022

Hello world!

Just a start….

  • Playing AWS Lightsail with Cloudfront
  • Moved the cicd-demo here
  • Completed the setup in Google Domain
  • What’s next? 😀

Read More