How to Fix the HTTP to HTTPS Redirect (301) on Your Site

Your site loads over HTTPS, but a request to the http:// version either serves the page unencrypted, fails, or uses a temporary (302/307) redirect. By the end of this guide, every http:// URL will return a permanent 301 or 308 redirect to the matching https:// URL, with the path and query string preserved, in a single hop.

By Updated ⏱ 15 minutes🎯 Beginner● High impactTechnical
Illustration: HTTP → HTTPS redirect fix guide
TECHNICAL · FIX GUIDE HTTP → HTTPS redirect IMPACTEFFORT TIME15 minutes LEVELBeginner

Why it matters

Without a permanent redirect, Google and other crawlers can index two copies of every page (http and https), which splits link signals and can surface the insecure version in search results and AI answers. Visitors who type example.com or follow old http:// links may land on an unencrypted page, where browsers show a "Not secure" warning and form data can be intercepted. A temporary 302 or 307 tells search engines the move may be reversed, so they may keep the http:// URL as canonical.

✕Beforecurl -I http://example.com/pricing →HTTP/1.1 200 OK (page servedunencrypted) or HTTP/1.1 302 Found →✓Aftercurl -I http://example.com/pricing →HTTP/1.1 301 Moved Permanently,Location: https://example.com/pricing

What you need

A working SSL/TLS certificate on your domain (Let's Encrypt, your host's free certificate, or a CDN certificate)
Access to your server config (Nginx/Apache), hosting control panel, or CDN dashboard
A terminal with curl, or an online HTTP header checker
Your preferred hostname decided: example.com or www.example.com

Step-by-step fix

1

Confirm HTTPS works before redirecting

Redirecting to a broken HTTPS site locks visitors out, so check the certificate first. Load https://example.com and https://www.example.com in a browser and confirm there is no certificate warning. The certificate must cover every hostname you redirect, including www.

text
curl -sI https://example.com | head -n 1
curl -sI https://www.example.com | head -n 1
Pro tip: If the www hostname shows a certificate error, add it to your certificate (e.g. certbot --nginx -d example.com -d www.example.com) before continuing.
2

Record how http:// currently responds

Request the plain HTTP version of your homepage and an inner page with a query string. Note the status code and the Location header. You are looking for:

  • 200 OK: no redirect at all (fail)
  • 302 or 307: temporary redirect (warning)
  • 301 or 308 to an https:// URL: already correct
  • No response / connection refused: port 80 is closed (fail)
text
curl -sI "http://example.com/" | grep -iE '^HTTP|^location'
curl -sI "http://example.com/blog/post?ref=news" | grep -iE '^HTTP|^location'
Pro tip: Port 80 must stay open. Closing it does not count as a redirect; anyone typing example.com without https gets a connection error.
3

Add a 301 redirect in Nginx

Create (or edit) a server block that listens on port 80 for all your hostnames and returns a 301 to the HTTPS version of your preferred hostname. $request_uri keeps the full path and query string. Remove any old return 302 or `rewrite ...

redirect` rules for port 80, then test and reload.

nginx
server {
  listen 80;
  listen [::]:80;
  server_name example.com www.example.com;
  return 301 https://example.com$request_uri;
}

# then run:
# sudo nginx -t && sudo systemctl reload nginx
Pro tip: Keep a location for /.well-known/acme-challenge/ only if your certificate renewal uses HTTP-01 and is not handled by certbot's own config; certbot --nginx manages this for you.
4

Or add a 301 redirect in Apache (.htaccess)

On Apache or shared hosting, put this at the top of the .htaccess file in your web root, above any WordPress or CMS rules. R=301 makes it permanent; without it Apache defaults to a 302. If your host sits behind a load balancer or CDN, use the X-Forwarded-Proto condition instead of %{HTTPS} to avoid redirect loops.

apache
RewriteEngine On
RewriteCond %{HTTPS} off
# Behind a proxy/CDN, use this line instead of the one above:
# RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]
Pro tip: If you have access to the virtual host config, a dedicated <VirtualHost *:80> with "Redirect permanent / https://example.com/" is faster than .htaccess.
5

Make it one hop to the canonical URL

Send http://www.example.com straight to https://example.com, not to https://www.example.com and then on again. Chains like http → https → non-www waste crawl budget and slow the first visit. Also check that the target URL keeps the original path and query string instead of dumping everyone on the homepage.

text
curl -sIL "http://www.example.com/about?x=1" | grep -iE '^HTTP|^location'
Pro tip: The output should show exactly one 301 followed by a 200. Two or more 3xx lines means you have a chain to collapse.
6

Update internal references to https://

Change your CMS site URL, canonical tags, XML sitemap and hard-coded internal links to https://example.com so you don't rely on the redirect for your own pages. Then add the https:// property in Google Search Console if you only had the http:// one, and resubmit the sitemap.

html
<link rel="canonical" href="https://example.com/pricing">
Pro tip: Once the 301 has been stable for a few weeks, add an HSTS header (Strict-Transport-Security: max-age=31536000; includeSubDomains) so browsers skip the http request entirely.
7

Verify the redirect status and target

Re-run curl against several URLs: the homepage, a deep page, a URL with a query string, and the www variant. Each must return 301 (or 308) with a Location starting with https://. Finally, re-run the audit to confirm the check passes.

text
for u in http://example.com/ http://www.example.com/ http://example.com/blog/post?ref=1; do echo "$u"; curl -sI "$u" | grep -iE '^HTTP|^location'; done
Pro tip: Test with curl, not your browser. Browsers cache 301s and HSTS, so they may show https:// even when the server is still misconfigured.

Platform-specific notes

WordPress

Set both WordPress Address (URL) and Site Address (URL) to https://example.com under Settings → General. Then add the redirect at server level (Nginx block or .htaccess rule above the # BEGIN WordPress section) or use your host's "Force HTTPS" toggle (e.g. in cPanel: Domains → Force HTTPS Redirect). Plugins like Really Simple SSL work but the server-level rule is faster and returns a clean 301.

Shopify

You cannot edit server config. Shopify issues SSL automatically and redirects http:// to https:// with a 301 for connected domains. If the check fails, go to Settings → Domains, confirm SSL shows as active for every domain, and set your primary domain; pending SSL usually means DNS records (A record 23.227.38.65, CNAME shops.myshopify.com) are wrong.

Cloudflare

Turn on SSL/TLS → Edge Certificates → Always Use HTTPS, which returns a 301 at the edge. Set SSL/TLS encryption mode to Full (strict); Flexible mode combined with an origin-level HTTP→HTTPS redirect causes an infinite redirect loop. Avoid Page Rules or Redirect Rules that use a 302 status for this.

Next.js / Vercel

Vercel redirects HTTP to HTTPS automatically with a 308, which passes the check. Self-hosted Next.js should handle it at the reverse proxy (Nginx, load balancer). If you must do it in the app, add a redirect in next.config.js with source '/:path*', has: [{ type: 'header', key: 'x-forwarded-proto', value: 'http' }], destination 'https://example.com/:path*', permanent: true (this emits a 308).

Wix / Webflow / Squarespace

HTTPS and the HTTP redirect are managed by the platform. In Webflow, go to Site settings → Publishing → Advanced publishing options and make sure SSL is enabled, then republish. In Wix and Squarespace, HTTPS is on by default for connected domains; if http:// does not redirect, the domain is usually not fully connected (check DNS in the domain settings).

Check that it worked

✅ How to verify

  • Run curl -sI http://example.com/ and confirm the first line is HTTP/1.1 301 (or 308) and the Location header starts with https://.
  • Run curl -sIL on http://www.example.com/some-page?x=1 and confirm there is exactly one redirect and it lands on the same path and query on your canonical HTTPS host with a 200.
  • Use Google Search Console URL Inspection on an http:// URL and check that Google reports it as redirecting to the https:// version.
  • Re-run the audit and confirm the HTTP → HTTPS redirect check shows a pass.

⚠️ Common mistakes

  • Using a 302 or 307 (or an Apache RewriteRule without R=301), which the audit flags as a warning and search engines treat as temporary.
  • Redirecting every http:// URL to the homepage instead of the matching https:// path, which breaks old links and loses page-level rankings.
  • Closing port 80 or removing the HTTP server block, so http:// requests time out instead of redirecting.
  • Combining Cloudflare Flexible SSL with an origin redirect to HTTPS, creating an endless redirect loop.

Is this still an issue on your site? Run a free audit — ZORO checks this and 294 other SEO, AI-visibility, accessibility and security signals, with fixes for your platform.

Check my site free

FAQ

Should an HTTP to HTTPS redirect be 301 or 302?

Use a 301 (or 308). Both are permanent and tell search engines to transfer signals to the https:// URL and index it instead. A 302 or 307 is temporary, so the http:// URL may stay indexed.

Is a 308 redirect OK instead of a 301?

Yes. A 308 is permanent like a 301 but also preserves the request method (POST stays POST). Google treats 301 and 308 the same, and platforms like Vercel use 308 by default.

Do I still need a redirect if I use HSTS?

Yes. HSTS only works after a browser has visited your HTTPS site once (or if you're on the preload list), and crawlers and many tools ignore it. The server-side 301 is what handles first visits, old links and search engines.

Will redirecting HTTP to HTTPS hurt my SEO?

No, when done with a single 301 to the matching URL. Google passes ranking signals through permanent redirects and prefers HTTPS. Short fluctuations can happen while pages are recrawled, which you can speed up by resubmitting your https:// sitemap in Search Console.