Fix a broken record

How to Redirect HTTP to HTTPS (Force HTTPS)

By Kalenfy · Updated 27 June 2026 · 6 min read

How to Redirect HTTP to HTTPS (Force HTTPS)

TL;DR: If your site is reachable over plain http://, browsers show a "Not secure" warning and data can be intercepted. Fix it by redirecting all HTTP traffic to HTTPS with a 301, then enforce it permanently with the HSTS header. Below are the steps for the common setups. Scan your domain free to confirm HTTPS is enforced.

Why force HTTPS?

Having a certificate isn't enough if visitors can still load the http:// version — anyone on the same network could read or tamper with that traffic, and Chrome flags the page as "Not secure". A redirect makes sure every request ends up on the encrypted version.

Apache (.htaccess)

Add a rewrite that sends all HTTP requests to HTTPS:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Nginx

Add a server block that listens on port 80 and returns a permanent redirect:

server {
  listen 80;
  server_name yourdomain.com www.yourdomain.com;
  return 301 https://$host$request_uri;
}

Cloudflare (no server access)

If your DNS is on Cloudflare, turn on SSL/TLS → Edge Certificates → Always Use HTTPS. It redirects HTTP to HTTPS at the edge with no config files. You can also enable Automatic HTTPS Rewrites to fix mixed content.

Lock it in with HSTS

Once HTTPS works everywhere, add the Strict-Transport-Security header so browsers refuse to use HTTP at all next time. Start with a short max-age, confirm nothing breaks, then raise it. Only add preload when you're certain every subdomain is HTTPS.

Verify it worked

FAQ

Should the redirect be 301 or 302?

301 (permanent) — it's correct for SEO and lets browsers cache the redirect.

Do I still need the redirect if I have HSTS?

Yes. HSTS only applies after a browser's first secure visit; the redirect catches that first request and anyone HSTS hasn't reached yet.

Will forcing HTTPS hurt my SEO?

The opposite — HTTPS is a ranking signal, and a clean 301 preserves your existing rankings.

Want HTTPS forced and HSTS set without touching config files? Scan your domain, then reply to your report — we're developers and we'll lock it down for you.

Check your own domain — free

Kalenfy runs a passive scan of your SPF, DKIM, DMARC, DNSSEC, CAA and more, then gives you a downloadable PDF report with exact fixes. You see your grade first — no email needed to view it.

Scan my site free

Related guides