Guide · 3 min read

Fix HTTPS redirects and mixed content

One clean redirect to HTTPS, no insecure resources, and a certificate that renews itself.

Updated · HackGrade

Redirect HTTP to HTTPS

nginx
server {
    listen 80;
    server_name example.com www.example.com;
    return 301 https://example.com$request_uri;
}
.htaccess
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

On Cloudflare? Use SSL/TLS mode Full (strict). “Flexible” mode talks to your server over HTTP, which together with a server-side redirect causes an endless redirect loop.

Fix mixed content

Mixed content is anything loaded over http:// on an HTTPS page. Find it in DevTools → Console, or in your HackGrade results. In WordPress, update the site URLs under Settings → General, then replace old links in the database (try it with --dry-run first):

shell
wp search-replace 'http://example.com' 'https://example.com' --skip-columns=guid --dry-run

As a safety net, the CSP directive upgrade-insecure-requests makes browsers fetch http:// resources over https://.

Keep the certificate renewing

Certificate lifetimes are getting shorter across the industry, so renewal must be automatic. With certbot:

shell
sudo certbot renew --dry-run

Sources

Related guides

Free · Instant · No sign-up

Find out your grade before someone else does.

Passive scan. Nothing is attacked without your permission.

Free to start. Paid plans from $12 a month, or a one-time report for $29. See pricing

This page is in English. Translations are on the way.