Safari is automatically redirecting to an HTTPS site that does not exist
Overview
When I entered the URLhttp://localhost:1313
into the Safari web browser, it automatically redirected the request to https://localhost:1313
. No amount of manually retyping http
or cache clearing resolved the problem. After a bit of research, I determined the problem is caused by the HTTP Strict Transport Security cache. HSTS forces web browsers to only connect to a domain over the secure https
protocol.
In this example http://localhost:1313
is my Hugo development server. It never used HSTS https
, I am unsure why it Safari thought it was. This post details the steps necessary to clear the HSTS cache to allow unencrypted http
connections again.
Details
When the following URL is entered into Safari:
Safari automatically redirects to the non-existent HTTPS site:
Since the Hugo webserver does not speak https
the page would fail with the following error:
The problem is caused by an improper HSTS cache entry. This issue is resolved by opening the Safari settings by pressing command + ,
and selecting Privacy -> Manage Website Data...
:
In the settings menu, search for the site improperly redirecting to https
, in my example this is localhost
and 127.0.0.1
. Delete all matching entries:
The page will now load without redirecting to the https
page: