Jekyll: Redirect http to https
web jekyll html links redirect htaccess javascript
Simple redirect of http URLS to https in Jekyll/Markdown using Javascript code.
Situation
This Jekyll blog site is generated by committing to Azure Devops which builds and releases it as an Azure Blob Storage Static Web Site. Unlike Azure Static Web Apps, Azure Storage Static Web Sites do not have a TLS/SSL option. Azure CDNs are used with this site to get the site URL into http://www.<customdomain>
then into https://<myname>.<customdomain>
. It is desirable to serve up only through SSLs/TLSs and so redirect the http
Urls to https
. Normally it is simple to map http://mydomain.com
to https://mydomain.com
. But in this case there is the complication of mapping www
to <myname>
as well.
On this site <myname>.<customdomain>
is davidjones.sportronics.com.au
In the code below, this is me.mydomain.com
Baby steps
An .htaccess file was tried but this is an Apache server so it didn’t work. Also …
… was also tried. This worked on the development machine but not when deployed to Azure via Azure DevOps.
Javascript Solution (Updated)
Map http://www.mydomain.com
to https://me.mydomain.com
using Javascript.
Update
Added ability to stop redirection on a specific page by adding the noredirect
page property in the page’s FrontMatter. Value doesn’t matter. If that property exists the redirection doesn’t occur for that page. This is useful in development mode!
This code is included in the post page template and the index page and so all http are automatically redirected to https without any code needed in the post .md pages.
⭐ This works fine. No need for .htaccess file and minimal Jekyll Liquid code required, etc.⭐
Topic | Subtopic | |
Next: > | Blazor Helpers App Members | 1. Overview of adding a Members Table |
This Category Links | ||
Category: | Web Sites Index: | Web Sites |
Next: > | Meltdown | Intro - A Simple Markup Parser |
< Prev: | Azure Static Web Apps | General Availability May 12 2021 |