You installed an SSL certificate, your site loads at https:// — but visitors typing the plain address (or arriving from old links) still land on the insecure http:// version. The fix is an HTTPS redirect: a rule that automatically sends every HTTP request to its HTTPS equivalent, so nobody ever browses your site unencrypted.
This guide shows how to set it up correctly on every common stack — Apache (.htaccess), Nginx, WordPress, and cPanel — plus how to verify it, the mistakes that cause redirect loops and mixed content, and what an HTTPS migration means for your SEO.
To redirect HTTP to HTTPS on Apache, add this to your .htaccess file (with an SSL certificate already installed):
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]Always use a 301 (permanent) redirect so search engines transfer your rankings to the HTTPS version.
Table of Contents
Before you start: two prerequisites
1. A valid SSL certificate must already be installed. This surprises many people: the TLS negotiation between browser and server happens before the server can even answer with a redirect. If there’s no valid certificate, visitors get a security error instead of being redirected. So the order is always: install the certificate first, redirect second. (See what an SSL certificate is — most hosts include a free one, often installable in one click, as in our Let’s Encrypt guide.)
2. Use a 301, not a 302. The move to HTTPS is permanent, and only a 301 redirect tells search engines to transfer the old URLs’ ranking signals to the new https:// versions. A 302 (temporary) here is one of the most common technical SEO mistakes.
One more rule of thumb: do the redirect at the server level, as shown below — meta-refresh tags and JavaScript redirects are slower, unreliable for SEO, and treated as second-class signals by search engines.
With those in place, pick your stack below.
Method 1: Apache / .htaccess (most shared hosting)
On Apache servers — which includes most shared hosting accounts — the redirect lives in the .htaccess file at your site’s root (note the leading dot). Add:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]Line by line: RewriteCond %{HTTPS} off matches only requests that arrived without encryption, and the rule sends them to the same host and path over https:// with a permanent 301. If your .htaccess already has RewriteEngine On, don’t duplicate it — place the two lines right after the existing one, before other rewrite rules (like WordPress’s).
To also force www or non-www in the same hop (avoiding a redirect chain), combine them into a single rule — for example, forcing HTTPS + non-www:
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [L,R=301]Method 2: Nginx
On Nginx, the clean approach is a dedicated server block for port 80 that returns a 301 to the HTTPS version:
server {
listen 80;
server_name example.com www.example.com;
return 301 https://example.com$request_uri;
}Your main server block then listens on 443 with the certificate configured. After editing, test the config (nginx -t) and reload (systemctl reload nginx). This “separate block + return 301” pattern is faster and more predictable than rewrite rules.
Method 3: WordPress
WordPress needs the redirect and its own settings aligned (otherwise you risk a loop):
- Update the site URLs. In Settings → General, set both WordPress Address (URL) and Site Address (URL) to the https:// version.
- Add the redirect via .htaccess (Method 1, placed before the WordPress block) — or use a plugin like Really Simple SSL, which handles the redirect and settings in one step.
- Fix old internal URLs. Use a search-replace plugin (like Better Search Replace) to update hardcoded http:// links in content and avoid mixed content.
If you can’t access the dashboard, the URLs can be forced in wp-config.php:
define( 'WP_HOME', 'https://example.com' );
define( 'WP_SITEURL', 'https://example.com' );Method 4: cPanel (one click)
Most cPanel hosts include a built-in toggle: go to Domains, find your domain, and switch Force HTTPS Redirect on. cPanel writes the 301 for you — no file editing. (The option only appears if an SSL certificate is installed, reinforcing prerequisite #1.) For other redirect types in cPanel, see our general guide on URL redirection methods.

Method 5: Windows / IIS
On Windows servers running IIS, the redirect is defined in the site’s web.config file (it requires the URL Rewrite module, installed on most IIS setups). Add this rule:
<rewrite>
<rules>
<rule name="HTTPS Redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>The rule matches any request that arrived with HTTPS off and issues a permanent (301) redirect to the same host and path over https://. The same logic can be configured visually in IIS Manager under URL Rewrite → Blank rule.
Behind Cloudflare? The dashboard has its own switch: SSL/TLS → Edge Certificates → Always Use HTTPS, which redirects at the edge before traffic reaches your server. If you enable it, keep the origin rule or the Cloudflare rule — not both fighting each other — and make sure the SSL mode is Full (strict) to avoid the loop described below.

How to verify the redirect
Don’t trust the browser alone — it caches redirects. Check the raw response:
curl -I http://example.comHTTP/1.1 301 Moved Permanently
Location: https://example.com/You want to see 301 (not 302) and the correct https:// destination. Add -L to follow the chain and confirm it’s a single hop — http://example.com should go straight to the final https:// URL, not bounce through intermediate versions. An online redirect checker does the same from a neutral server.

http → https → www → final is three hops where one would do. Every extra hop adds latency and dilutes SEO signals. Configure your rules so any old URL reaches the final https:// version in a single 301.
Common problems (and fixes)
ERR_TOO_MANY_REDIRECTS (redirect loop). The classic cause: two layers each forcing the opposite protocol — e.g., your server redirects HTTP→HTTPS while a CDN/proxy (like Cloudflare in “Flexible” SSL mode) sends HTTPS back to origin as HTTP, triggering the rule again forever. Fix: make only one layer force HTTPS, and set Cloudflare to Full (strict). In WordPress, mismatched Site URLs cause the same loop. (Full walkthrough in our HTTP 302 guide, which covers loops in depth.)
Mixed content warnings. The page loads over HTTPS but still references images/scripts/CSS via http:// — the padlock breaks or the browser blocks resources. Fix: update internal URLs to https:// (or protocol-relative), run a search-replace in the database on WordPress, and check themes/plugins that hardcode http://.
The redirect works, but the padlock shows an error. That’s a certificate problem, not a redirect problem — expired, wrong domain, or incomplete chain. Revisit the SSL certificate installation.
Some pages redirect, others don’t. Usually a rule placed after other rewrite rules that short-circuit it (move the HTTPS rule to the top), or a subdomain not covered by the certificate/rule.
HTTPS migration and SEO
Redirecting to HTTPS isn’t just security — it’s an SEO migration, and handled correctly it protects and helps your rankings:
- The 301 transfers your link equity. Search engines treat the https:// URLs as the new canonical addresses and pass essentially all ranking signals to them in a single hop.
- Expect a brief settling period. Google needs to recrawl and reindex the HTTPS URLs; small fluctuations for a few days or weeks are normal. A permanent drop is not — it usually means chains, loops, or missed redirects.
- Update the ecosystem: add the https:// property in Google Search Console, resubmit the sitemap with https:// URLs, update canonical tags to https://, and fix internal links so they point directly at the final URLs (not through the redirect).
- HTTPS itself is a ranking signal — Google has confirmed it, and modern speed protocols (HTTP/2, HTTP/3) only work over HTTPS, so the migration typically makes the site faster too. (More on that in our HTTP vs HTTPS guide.)
Going further: HSTS. Once the redirect has run stably, you can add the Strict-Transport-Security header, which tells browsers to always connect via HTTPS directly — removing even the first insecure hop — the exact gap a man-in-the-middle attack exploits via SSL stripping.. Enable it only after confirming everything works over HTTPS, as it’s hard to undo.
Frequently asked questions
How do I redirect HTTP to HTTPS?
Install an SSL certificate first, then add a 301 redirect rule for your stack: a RewriteRule in .htaccess on Apache, a return 301 server block on Nginx, the Force HTTPS toggle in cPanel, or a plugin like Really Simple SSL on WordPress. Verify with curl -I that HTTP answers with 301 to the https:// URL.
Should the HTTPS redirect be a 301 or 302?
Always a 301 (permanent). The move to HTTPS is definitive, and only a 301 tells search engines to transfer the old URLs’ ranking signals to the HTTPS versions. A 302 can leave your rankings stuck on the old HTTP URLs.
Do I need an SSL certificate before redirecting?
Yes — it’s mandatory. The TLS handshake happens before the server can send the redirect response, so without a valid certificate visitors get a security error instead of the redirect. Certificate first, redirect second.
Why am I getting ERR_TOO_MANY_REDIRECTS after forcing HTTPS?
Two layers are fighting: typically the server forces HTTPS while a CDN/proxy (like Cloudflare on “Flexible” SSL) talks to the origin over HTTP, re-triggering the rule in a loop. Keep the HTTPS redirect in one layer only and set the CDN’s SSL mode to Full (strict). In WordPress, also confirm both Site URLs use https://.
Does redirecting to HTTPS hurt SEO?
Done correctly (single-hop 301s, updated sitemap and canonicals), no — small fluctuations for a few days are normal, and afterward HTTPS helps: it’s a Google ranking signal and enables the faster HTTP/2 and HTTP/3 protocols.
Copahost hosting comes with a free SSL certificate and easy HTTPS enforcement — plus full .htaccess access when you want to fine-tune your redirects yourself. Secure, fast, and SEO-friendly from day one.
Explore Copahost hostingConclusion
Redirecting HTTP to HTTPS is a small configuration with an outsized payoff: every visitor browses encrypted, browsers stop flagging your site, and — done with clean single-hop 301s — your SEO transfers intact and even improves. The recipe is the same on any stack: certificate installed first, one permanent redirect rule in one layer, verify with curl, fix mixed content, and update Search Console and your sitemap. From there, HTTPS on port 443 simply becomes the only way anyone reaches your site — exactly as the modern web expects.
