Ahosting Logo
Knowledge Base

How to Force HTTPS and Redirect HTTP to HTTPS

After installing SSL, you should redirect all HTTP traffic to HTTPS. This ensures visitors always use the secure version of your site.

Why Force HTTPS?

  • Visitors typing your domain without https:// get redirected automatically
  • Old bookmarks and links still work
  • Search engines see one canonical version (better for SEO)
  • Prevents accidental unencrypted access

Method 1: .htaccess (Apache/LiteSpeed)

Add this code to the top of your .htaccess file in your web root:

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

Also Redirect www to non-www (or vice versa)

# Force HTTPS and non-www
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www. [NC]
RewriteRule ^(.*)$ https://yourdomain.com/$1 [L,R=301]

Method 2: cPanel Redirects

  1. Log into cPanel
  2. Go to Domains ? Redirects
  3. Select your domain
  4. Set redirect from http:// to https://
  5. Choose Permanent (301)
  6. Click Add

Method 3: WordPress Settings

  1. Go to Settings ? General
  2. Change WordPress Address (URL) to https://
  3. Change Site Address (URL) to https://
  4. Save

Then add the .htaccess redirect above.

Method 4: WordPress Plugin

Install Really Simple SSL plugin:

  1. Install and activate the plugin
  2. Click "Go ahead, activate SSL!"
  3. The plugin handles redirects and mixed content

Verify Your Redirect

Test that redirects work correctly:

  1. Visit http://yourdomain.com — should redirect to https://
  2. Visit http://www.yourdomain.com — should redirect to https://
  3. Check with curl: curl -I http://yourdomain.com
  4. Look for "301 Moved Permanently" and "Location: https://..."

Common Issues

  • Redirect loop: Your server may already be handling SSL. Remove duplicate redirect rules.
  • Mixed content after redirect: Update internal links to use https://
  • Cloudflare issues: Set SSL mode to "Full" or "Full (Strict)" in Cloudflare

Important: Use 301 (permanent) redirects, not 302 (temporary). This tells search engines to update their index.