Home / Fix guides / Website security

How to redirect HTTP to HTTPS

Your site should send anyone who opens the http:// address straight to the https:// address with a permanent (301) redirect. If it does not, the insecure version stays live, and the fix is a single redirect rule on your server, host or CDN.

When someone types http://yourdomain.com, your website should automatically send them to https://yourdomain.com. If it does not, visitors can land on an old, unencrypted copy of your site, and search engines see two versions of every page. This is common after installing an SSL certificate, because the certificate makes https work but does not force anyone to use it.

What the problem looks like

You may notice one or more of these:

  • The https:// version loads with a padlock, but the http:// version loads too and stays on http://.
  • The browser shows "Not secure" in the address bar for visitors who arrive on the http version.
  • Some pages redirect and others do not.
  • Only the www or only the non-www version redirects.

Why it matters

  • Security: Anything sent over plain http can be read or changed on the way, for example on public Wi-Fi. That includes contact forms, logins and checkout details.
  • Trust and sales: Browsers can label http pages as not secure, especially pages with forms. Customers who see that warning may leave before they contact you or pay.
  • Search: Search engines treat http and https as separate addresses. Without a redirect, links and visits can be split between two copies of the same page, and the wrong one may show in results.
  • Next steps: Security headers such as HSTS only make sense once the redirect works. See missing HSTS header.

How to check your site (free)

  1. Open a private browser window and type http://yourdomain.com (include the http://). Watch the address bar. It should change to https:// by itself.
  2. Repeat with http://www.yourdomain.com and with an inner page such as http://yourdomain.com/about.
  3. For a precise answer, run this in a terminal (Mac, Linux, or Windows 10 and later):
curl -I http://yourdomain.com

You want to see a status of 301 and a line like Location: https://yourdomain.com/. A 200 status means the page simply loaded over http with no redirect. A 302 works but is temporary, so change it to 301.

  1. Free online redirect checkers such as httpstatus.io show every hop in the chain, which helps if you suspect more than one redirect.

Before you fix it: make sure the certificate works

A redirect to a broken https address is worse than no redirect, because visitors will hit a full-page warning. Open the https version first and check that it loads with a padlock on both the www and non-www names. If you see a warning, fix that first, starting with SSL certificate name mismatch. Many hosts provide free certificates (often from Let's Encrypt) with a switch in their control panel.

How to fix it

The goal is one permanent (301) redirect from every http address to the matching https address, keeping the page path. Do it in one place only. Stacking a plugin rule, a server rule and a CDN rule is the usual cause of redirect loops. Also decide whether your main address uses www or not, and make all four versions (http and https, with and without www) end up there.

Where you set it depends on how your site is hosted:

  • WordPress: First set both the WordPress Address and Site Address to https:// under Settings, General (some hosts lock these). Then add the redirect at server level or use your host's force-HTTPS option. Plugins such as Really Simple SSL can do it if you prefer. See the WordPress guide.
  • Apache (`.htaccess`): Add this near the top of the .htaccess file in your site's root folder, and keep a backup first:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
  • Nginx: Use a separate server block for port 80 that does nothing but redirect, then reload Nginx:
server {
    listen 80;
    server_name yourdomain.com www.yourdomain.com;
    return 301 https://$host$request_uri;
}
  • cPanel hosting: Newer versions have a "Force HTTPS Redirect" switch for each domain under Domains. Older versions need the .htaccess rule above. It depends on your host's version.
  • Cloudflare: Under SSL/TLS, Edge Certificates, turn on "Always Use HTTPS". Set the SSL/TLS mode to Full (strict) first (this needs a valid certificate on your own server, otherwise visitors may see errors), as "Flexible" mode is a common cause of loops when your own server also redirects.
  • Shopify, Wix, Squarespace and similar builders: These usually handle it for you once the domain is connected and the certificate is active. Look for an SSL or HTTPS setting in the domain or security settings, and check whether your primary domain is set correctly.
  • IIS (Windows servers): Install the URL Rewrite module and add a rule that redirects requests where HTTPS is off to the https address with a 301.

If you are not comfortable editing server files, ask your host's support or your developer. Sending them the result of the curl check above saves time.

Clean up after the redirect

  • Update hard-coded http:// links to images, scripts and stylesheets. Otherwise pages can show "mixed content" warnings even though the redirect works.
  • Make sure canonical tags, your sitemap and internal links use https://.
  • In Google Search Console, add the https version of your site if it is not there already, and submit the https sitemap.

How to confirm the fix worked

  1. Test in a private window, because browsers remember 301 redirects and may show old behaviour.
  2. Check all four variants: http:// and https://, with and without www. Each should reach your chosen address in one step.
  3. Check an inner page and a URL with a query string, such as ?page=2. The path and query should carry over.
  4. Run curl -I again and confirm a single 301 followed by a 200 on the https address.
  5. Click through key pages and look for the padlock and for mixed content warnings.

How to stop it coming back

  • Turn on automatic certificate renewal, and check your https address after any renewal change.
  • Re-test after a hosting move, a theme or plugin change, a new CDN or a domain change. These often overwrite redirect rules.
  • Keep a note of where the redirect lives (server file, plugin, CDN) so nobody adds a second one.
  • Once everything is stable, add HSTS so browsers go straight to https. Read about HSTS before enabling it, since it is hard to undo quickly.
  • Check regularly. SiteMonday covers this in week 10 (domain, SSL and email deliverability), where your report lists what it finds in a ranked fix list. It finds and explains problems, and fixing them is up to you or your developer.

Step by step for your platform

Questions

Should I use a 301 or a 302 redirect?

Use a 301 (permanent) redirect, because it tells browsers and search engines that https is the lasting address. A 302 is meant for temporary moves.

Will redirecting to HTTPS hurt my search rankings?

A single, correct 301 from each http page to its https equivalent is the standard way to move, so it should not harm you. Problems usually come from redirect chains, loops or pages that redirect to the home page instead of the matching page.

Why do I get a "too many redirects" error after fixing it?

Usually two things are redirecting at once, or your site sits behind a CDN or proxy that connects to your server over http. Keep one redirect rule, and with Cloudflare use Full (strict) rather than Flexible mode.

Do I also need to redirect the www version?

Yes. Pick either `www` or non-`www` as your main address and make all four variants, http and https with and without `www`, lead to it.

Is installing an SSL certificate enough?

No. The certificate lets https work, but visitors can still open the http version unless you add a redirect.

Does a redirect cost anything?

The redirect itself is free, as it is a setting or a few lines of configuration. Many hosts also include a free certificate, though your hosting plan may vary.

Related problems