How to Fix HTTP to HTTPS Redirect

Got SSL but traffic still hits HTTP? Users and search engines may keep landing on the insecure version. A 301 (permanent) redirect from HTTP to HTTPS fixes that, everyone ends up on the secure URL and search engines treat it as canonical. Here's Nginx, Apache, Cloudflare, and WordPress.

Key takeaways

  • Use a 301 redirect so search engines treat HTTPS as the canonical URL.
  • Configure the redirect at the server (Nginx/Apache), CDN (Cloudflare), or via WordPress settings and plugins.
  • Install an SSL certificate first; the redirect then sends HTTP traffic to the HTTPS version.
  • Verify the redirect with our free HTTPS checker, you’ll see the chain and status code (301 vs 302).

Why redirect HTTP to HTTPS?

No redirect? Then anyone typing http://yoursite.com or following an old link stays on HTTP. You get unencrypted traffic, “Not Secure” in the browser, and split SEO, Google might index both versions. A 301 sends everyone to HTTPS, keeps data encrypted, and pulls ranking signals onto the secure URL.

Before you redirect

Obtain and install an SSL/TLS certificate on your server or use your host/CDN’s certificate. The redirect only works once HTTPS is valid; otherwise users would land on a certificate error.

How to redirect HTTP to HTTPS in Nginx

Add a server block for port 80 that 301s to HTTPS. Swap example.com for your domain.

  1. Open your Nginx config (e.g. /etc/nginx/sites-available/default or a site-specific file).
  2. Add this server block (or update the existing one for port 80):

$host is the hostname, $request_uri is path and query, so the redirect keeps the same URL, just on HTTPS.

  1. Test the config: sudo nginx -t
  2. Reload Nginx: sudo systemctl reload nginx (or sudo service nginx reload)

How to redirect HTTP to HTTPS in Apache (.htaccess)

If you use .htaccess, add these lines. Ensure mod_rewrite is enabled.

  1. Open the .htaccess file in your site’s root (e.g. public_html).
  2. Add or merge this block:

Save the file. If you edit the main Apache config instead, restart Apache after changes (sudo systemctl restart apache2 or sudo service apache2 restart). If your server is behind a proxy or load balancer that terminates SSL, %{HTTPS} may always be off; in that case use RewriteCond %{HTTP:X-Forwarded-Proto} !https instead.

How to redirect HTTP to HTTPS in Cloudflare

With Cloudflare you can do the redirect at the edge, so your origin doesn’t have to.

  1. In the Cloudflare dashboard, select your domain.
  2. Go to SSL/TLSEdge Certificates.
  3. Turn on Always Use HTTPS. Cloudflare will redirect all HTTP requests to HTTPS with a 301 (permanent) redirect at the edge, no origin redirect needed (and Cloudflare recommends not redirecting at the origin to avoid loops).
  4. If you need a custom rule (e.g. only certain paths): go to RulesRedirect Rules → Create rule, match HTTP requests, and set the target URL to preserve host and path (e.g. dynamic target https://${host}${uri} or your dashboard’s equivalent), with status 301.

How to redirect HTTP to HTTPS in WordPress

First switch the site URL to HTTPS in WordPress; then make sure the server or a plugin actually redirects HTTP to HTTPS.

  1. Log in to the WordPress dashboard.
  2. Go to SettingsGeneral.
  3. Set WordPress Address (URL) and Site Address (URL) to https://yourdomain.com.
  4. Click Save Changes.
  5. Ensure the HTTP→HTTPS redirect is in place: your host may do it automatically, or use a plugin like Really Simple SSL. If you manage the server, use the Nginx or Apache steps above.

How to verify your HTTPS redirect

Once it’s in place, try http://yourdomain.com in the browser, you should land on https://.... For the full chain and status code (301 vs 302), run your domain through our free HTTPS checker; you’ll get the chain, response times, and SSL grade in one go.

Check your domain with HTTPS Checker

Stuck? We’re happy to point you in the right direction or suggest next steps.

Contact us