Redirecting HTTP to HTTPS Using .htaccess File

Redirecting htt to https using .htaccess file, but make sure your site install SSL certificate, you can also see How to install SSL Certificate

Editing .htaccess in cPanel

  1. Login to cPanel
  2. Files > File Manager > Document Root for:
  3. Now select the domain name you want to access
  4. Check “Show Hidden Files (dotfiles)” See below Image
  1. After a new tab or window opens, look for the .htaccess file.
  2. Right click on the .htaccess file and click on “Code Edit” on the menu.
  3. A dialogue box may pop up asking about encoding. Click the “Edit” button to continue.
  4. Edit the file
RewriteEngine On

### WWW & HTTPS

# ensure www.
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# ensure https
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
  1. “Save Changes”.
  2. Test your website to make sure it is done correctly.

Related Posts

Sorry, no related articles to display.

Leave a reply