• Skip to main content
  • Skip to secondary menu
  • Skip to primary sidebar
  • Skip to footer
downloadbytes

DownloadBytes.com

Download Free Software

  • Home
  • Software
    • Antivirus
    • Graphics
    • Internet
    • Multimedia
    • Office
    • Utilities
  • Games
  • SEO Tools
  • Operating Systems
  • Android
  • Blog
  • Help

How To Redirect HTTP To HTTPS Using htaccess

November 28, 2019 by admin Leave a Comment

In this tutorial, you will learn how to redirect your website from HTTP to HTTPS version using .htaccess file. In the world of Cyber Crime, it is necessary to use SSL to protect your website and user data. HTTPS adds a layer of security when transmitting data from a client to a server.

HTTPS stands for Hyper Text Transfer Protocol Secure. HTTPS makes it harder for hackers trying to steal confidential information such as credit card numbers, passwords, etc.

Requirements:

  1. SSL: You need to have an SSL certificate installed on your web server or hosting. You can check out this tutorial on how to install free SSL
  2. FTP Account: You will need an FTP account to edit your .htaccess file if using a VPS or dedicated server without cPanel. For cPanel users, they can go to cPanel and under Files module open File Manager. .htaccess file is in the home directory of your website which looks like /public_html.
redirect http to https using .htaccess

Redirecting HTTP to HTTPS in WordPress website

WordPress makes a default .htaccess file when installed.

Default WordPress code for .htaccess file is given below in case you mess the code and your site goes down you can use this code to reinstate your website.

# BEGIN WordPress

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

# END WordPress

.htaccess Code to redirect WordPress website from HTTP to HTTPS in shared hosting servers

Replace the default code with the code given below

Case1: Redirect http://yourdomain.com to https://www.yourdomain.com

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [R=301,L,NE]

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

Case2: Redirect http://www.yourdomain.com to https://yourdomain.com

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

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

.htaccess Code to redirect WordPress website from HTTP to HTTPS in hosting servers when the server is behind a firewall

Case1: Redirect http://yourdomain.com to https://www.yourdomain.com

RewriteEngine on
RewriteCond %{HTTP_HOST} ^yourdomain.com [NC]
RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [L,R=301]
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]

# BEGIN WordPress
# The directives (lines) between `BEGIN WordPress` and `END WordPress` are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

Case2: Redirect http://www.yourdomain.com to https://yourdomain.com

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.yourdomain.com [NC]
RewriteRule ^(.*)$ https://yourdomain.com/$1 [L,R=301]
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]

# BEGIN WordPress
# The directives (lines) between `BEGIN WordPress` and `END WordPress` are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

Redirecting HTTP to HTTPS in HTML website(NON-Wordpress)

Case1: Redirect http://yourdomain.com to https://www.yourdomain.com

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [R,L]

Case2: Redirect http://www.yourdomain.com to https://yourdomain.com

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://yourdomain.com/$1 [R,L]

Share this:

  • Tweet
  • WhatsApp

Related

Filed Under: Blog

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Important Update

Hello Visitors

Now, We are sharing files through TeraBox. TeraBox is just like google drive or dropbox where you upload and share content. Watch Tutorial

Top Posts

  • GTA: San Andreas PC Game Free Download
  • GTA 4 Download For PC
  • Need For Speed Underground 2 Download For PC
  • GTA 3 Free Download For PC

Join Our Newsletter

Enter your email address to subscribe to this site.

Follow Us

  • Facebook
  • Twitter
  • YouTube

Footer

HOME  |   ABOUT  |  EULA  |  DISCLAIMER  |  PRIVACY  |  CONTACT
SSL Secure
Privacy & Cookies: This site uses cookies to enhance user experience. To find out more, see here Cookie Policy

Copyright © 2023 ยท [DownloadBytes.com]