How to Force HTTPS Redirect in .htaccess & Nginx (Copy-Paste Code)
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.
✅ 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
wwwversions resolve cleanly to one canonical HTTPS URL. - Verify your HTTPS property and
sitemap.xmlinside Google Search Console and Bing Webmaster Tools.