How to Redirect HTTP to HTTPS in .htaccess: Complete 301 Permanent Redirect Guide

Advertisement

Google AdSense In-Article Display Placement

Publisher ID: ca-pub-XXXXXXXXXXXXXXXX (Configured in config.php)

Enforcing HTTPS is critical for security, user trust, and SEO. Learn how to write bulletproof Apache mod_rewrite rules that permanently redirect all traffic to HTTPS without creating redirect loops.

✔ Rapid Direct Solution

Add this rule at the very top of your ".htaccess" file in public_html: RewriteEngine On -> RewriteCond %{HTTPS} off -> RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]. If behind Cloudflare proxy, use: RewriteCond %{HTTP:X-Forwarded-Proto} !https.

1. Problem Diagnosis & Symptoms

Without automatic redirects, search engines may index both HTTP and HTTPS versions, splitting link equity and causing duplicate content penalties.

2. Primary Root Causes

  • Cause: Missing redirect directives in web root.

3. Step-by-Step Diagnostic Fixes

1

Add Canonical HTTPS Rule in .htaccess

Edit public_html/.htaccess:

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

4. How to Verify the Resolution

  • ✔ Visit http://gardenwargame.online and confirm instant redirection to https://.

5. Diagnostic Troubleshooting Matrix

Symptom Observed Root Cause Recommended Action
ERR_TOO_MANY_REDIRECTS on HTTPS SSL proxy passes decrypted HTTP to origin while origin checks %{HTTPS} off Use RewriteCond %{HTTP:X-Forwarded-Proto} !https instead of %{HTTPS} off

6. Critical Mistakes to Avoid

  • ❌ Using temporary 302 redirects instead of permanent 301 redirects.

7. Frequently Asked Questions

❓ Does a 301 redirect pass full Google PageRank?

Yes, Google officially confirmed that 301 redirects transfer full PageRank equity.

Official Technical References

Advertisement

Google AdSense In-Article Matched Content Unit