wordpress 2026-11-28

How to Force HTTPS Redirect in .htaccess & Nginx (Copy-Paste Code)

How to Force HTTPS Redirect in .htaccess & Nginx (Copy-Paste Code)
Quick Answer: To force HTTPS on Apache or LiteSpeed servers, add RewriteEngine On, RewriteCond %{HTTPS} off, and RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] at the very top of your .htaccess file.

Apache / LiteSpeed (.htaccess) Rule

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Nginx Server Block Rule

server {
    listen 80;
    server_name yourdomain.com www.yourdomain.com;
    return 301 https://$host$request_uri;
}

Important Note for Cloudflare Users

If you use Cloudflare behind Nginx/Apache, turn ON Always Use HTTPS inside Cloudflare instead of adding duplicate .htaccess rules if you experience redirect loops, or ensure Cloudflare is set to Full (Strict).

Frequently Asked Questions

Does a 301 HTTPS redirect hurt Google SEO? No, a 301 permanent redirect passes full link equity to your HTTPS URLs. Verify your canonicals with our SEO Checker.

↪️ Generate .htaccess & Nginx 301 HTTPS Redirects
Generate 301 Rules →

✅ Post-Installation Verification & SEO Checklist

After applying the steps above, run through this 5-point checklist to prevent browser warnings and protect your Google SEO rankings:

  • Verify full CA chain trust and TLS 1.3 support using our Live SSL Checker.
  • Scan for Mixed Content HTTP links and check HSTS/CSP headers on Security Headers Checker.
  • Enforce a permanent 301 HTTP-to-HTTPS redirect with our HTTPS Redirect Generator.
  • Confirm both root and www versions resolve cleanly to one canonical HTTPS URL.
  • Verify your HTTPS property and sitemap.xml inside Google Search Console and Bing Webmaster Tools.

Certificados SSL Grátis, Verificador SSL e Gerador CSR

Emita certificados SSL Let's Encrypt e Buypass confiáveis em 60 segundos.

Related Articles