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.
- Open your Nginx config (e.g.
/etc/nginx/sites-available/defaultor a site-specific file). - Add this server block (or update the existing one for port 80):
server {
listen 80;
server_name example.com www.example.com;
return 301 https://$host$request_uri;
}$host is the hostname, $request_uri is path and query, so the redirect keeps the same URL, just on HTTPS.
- Test the config:
sudo nginx -t - Reload Nginx:
sudo systemctl reload nginx(orsudo service nginx reload)
How to redirect HTTP to HTTPS in Apache (.htaccess)
If you use .htaccess, add these lines. Ensure mod_rewrite is enabled.
- Open the
.htaccessfile in your site’s root (e.g.public_html). - Add or merge this block:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]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.
- In the Cloudflare dashboard, select your domain.
- Go to SSL/TLS → Edge Certificates.
- 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).
- If you need a custom rule (e.g. only certain paths): go to Rules → Redirect 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.
- Log in to the WordPress dashboard.
- Go to Settings → General.
- Set WordPress Address (URL) and Site Address (URL) to
https://yourdomain.com. - Click Save Changes.
- 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.
Stuck? We’re happy to point you in the right direction or suggest next steps.
Contact us