• 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
    • Operating Systems
  • Games
  • Online Games
  • SEO Tools
  • MODS
    • ANDROID
  • Ocean of Games
  • Blog
  • Help

How To Redirect HTTP To HTTPS Using htaccess

Last updated on October 15, 2024 by admin

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 buy ssl certificate to install on your web server or hosting.
  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:

  • Facebook
  • X

Like this:

Like Loading...

Related

Filed Under: Blog

Reader Interactions

Leave a Reply Cancel reply

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

Primary Sidebar

Free WEB Hosting No Credit Card required

100% Free Web Hosting

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

  • Komikus Fasik APK 3.0 Free Download
    Komikus Fasik APK 3.0 Free Download
  • Pokemon Ecchi Version Download
    Pokemon Ecchi Version Download
  • WWE 2k21 PPSSPP – PSP Apk Iso Download Android
    WWE 2k21 PPSSPP – PSP Apk Iso Download Android
  • WWE 2k20 PPSSPP – PSP Apk Iso Download For Android
    WWE 2k20 PPSSPP – PSP Apk Iso Download For Android

Follow us

  • Twitter
  • YouTube

Subscribe to our blog

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 431 other subscribers

Footer

HOME  |   ABOUT  |  EULA  |  DISCLAIMER  |  PRIVACY  |  CONTACT
SSL Secure
Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Cookie Policy

Copyright © 2025 · [Downloadbytes.com]

%d