Redirect from http to https using .htaccess file in codeigniter OR wordpress

Redirect from http to https using .htaccess

If you have a website with HTTP and you have purchased the SSL for your site, then it’s hard to manage redirection because every request to your site has HTTP  before any request, so how can redirect your every request…?

If you want to add www with every request of your site, for instance, someone accessing your website without www( and you want to redirect from to how can you do that..?

If you are working on WordPress, then you have many options you can install a plugin like Really Simple SSL  you can find other plugins to redirect.

But why you need to install a plugin if you have many plugins already installed inside your project/theme.

If you are talking about Codeigniter, it’s easy to redirect your request using .htaceess, but before using .htaccess files in CodeIgniter OR WordPress, you have to familiar with .htaccess file.

What is SSL…?

SSL(Secure Sockets Layer) Certificates are small data files that digitally bind a cryptographic key to an organization’s details. When installed on a web server, it activates the padlock and the https protocol and allows secure connections from a web server to a browser.

What is .htaccess file..?

.htaccess is a configuration file for use on web servers running the Apache Web Server software.

Now we are going to add .htaccess file which redirects your request from HTTP to HTTPS.

Step 1: Create a .htaceess file in the root folder and copy this code in the file.

If you want to redirect your request from HTTP to https without installing any plugin, then just find the .htaccess file in your root directory and open it.

Find RewriteEngine On and copy this code below it.

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

You can also install a plugin to solve your redirect issue if you are not using code.

My Name is Shehzad Ahmed and I am a full-time developer with over 7+ years of experience. In that time, I’ve worked as a developer with many big and small firms and was teaching web design and development skills to many keen learners and by the time passes I’ve found a great passion and potential on myself as a teacher on this particular field and now I am a full-time teacher and working as a freelancer.


  • yogita patil
    November 5, 2019

    we are not able to redirect controller from the view..we have also set htaccess file..and remove index page from config..pls do the needful

    • shakzee
      November 8, 2019

      can you please explain your question..?

Leave a Reply

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

Featured Courses

Learn Web Development and web designing in few months from shakzee with real-world experience. Get up to 80% discount!