Redirect http to https using htaccess

Today we are going to show you how to Redirect from http to https using .htaccess file in codeigniter. If you have a website with HTTP and you have purchased the SSL for your site then you want to redirect from http to https it’s hard but not impossible to manage redirection because till now every request to your site has HTTP before any request so how can redirect your every request code is below.

http to https htacces example 1

Copy below code past inside you htaccess file, it will be redirect your website http to https

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{ENV:HTTPS} !=on
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
</IfModule>

http to https htacces example 2

This code will be work with several condition: phpkida.com to https://www.phpkida.com http://www.phpkida.com to https://www.phpkida.com https://phpkida.com to https://www.phpkida.com

RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [OR]
RewriteCond %{HTTP_HOST} ^phpkida\.com$ [NC]
RewriteRule ^ https://www.phpkida.com%{REQUEST_URI} [R=301,L,NE]
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /index\.php(/[^\ ]*)?\ HTTP/ 
RewriteRule ^index\.php(/(.*))?$ phpkida.com/$2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

http to https htacces example 3

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

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]

RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www.phpkida.com [NC]
RewriteRule (.*) https://www.phpkida.com/$1 [R=301,L]

You can also redirect http to https using php

Tags:

redirect to www htaccess codeigniter, codeigniter https htaccess, codeigniter: https not working, redirect http to https htaccess, codeigniter htaccess, redirect non www to www https, use ssl in codeigniter, htaccess redirect, Redirect from http to https using .htaccess file in codeigniter, How to redirect http to https in codeigniter

Author: Mukesh Jakhar

This is Mukesh Jakhar. I’m a professional web developer with 3+ years experience. I am always ready for freelance work and i am writing blogs in my free time. I love to learn new technologies and share with others.
I founded PHPKIDA in September 2015. The focus of this website to provide web development tutorials of PHP, WordPress, CodeIgniter, Jquery, MySQL, HMTL, CSS etc and sharing solution to problems which i already solved.

Leave a Reply

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

Related Posts: You may like

Online Directory Software – Local Business Directories Application

Pagination in CodeIgniter With Search Query

Codeigniter pagination with search query string

Minify HTML in CodeIgniter using Hooks

How to execute mysql query inside codeigniter helper

Upload and Resize Image and Create Thumbnail Codeigniter

Rename file while uploading in codeigniter

Pagination In CodeIgniter With Example

Upload file with database codeigniter

Simple codeigniter login system

PHPKIDA Offering Free Tools:

INSTA DOWNLOADER

Free online tool to download Instagram videos, photos and save Instagram videos, photos to your device. It's free & easy to use.

Download Now

CURRENCY CONVERTER

Our real time currency converter calculator will convert your money based on current values from around the world. It's free & easy to use.

Convert Now

ROBOST.TXT GEN.

Create robots txt file that help search engines to crawling and indexing your site with help of our free online Robots.txt Generator tool.

Create Now

HTML MINIFIER

Free online tool to minify or compress html code and reduce the size of html code in few clicks. It's free & easy to use.

Minify Now

CSS MINIFIER

Free online tool to minify or compress css code and reduce the size of css code in few clicks. It's free & easy to use.

Minify Now

JAVASCRIPT MINIFIER

Free online tool to minify or compress javascript code and reduce the size of javascript code in few clicks. It's free & easy to use.

Minify Now

Sign up for weekly update

Milkshake is almost ready. If you're interested in testing it out, then sign up below to get exclusive access.