Fix Mixed Content Errors Using .htaccess (HTTPS, Apache, CSP)
When your HTTPS website shows mixed content warnings due to HTTP resources, this article explains how to fix mixed content errors using .htaccess by adding a Content-Security-Policy header on Apache servers. This ensures all resources load over HTTPS and prevents browser mixed content errors.
To fix any mixed content-related error on any website we just need to add one line to the website directory .htaccess file:
Header always set Content-Security-Policy "upgrade-insecure-requests;"
How does this help ?
"Upgrade Insecure Requests" is a CSP (Content Security Policy) directive that allows us to indicate to HTTP clients/browsers that all resources must be accessed via HTTPS.
This allows users to migrate more easily to HTTPS websites or web apps that contain a great number of HTTP-declared resources. The application's resources will automatically be requested on HTTPS by the client/browser, without any mixed content alert.