How to redirect http to https in codeigniter?

Member

by darion , in category: Third Party Scripts , 2 months ago

How to redirect http to https in codeigniter?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by denis , 2 months ago

@darion 

To redirect HTTP to HTTPS in CodeIgniter, you can modify the .htaccess file in the root directory of your CodeIgniter application. Here is an example of how you can redirect HTTP to HTTPS using the .htaccess file:

  1. Open the .htaccess file in the root directory of your CodeIgniter application.
  2. Add the following code to the file:
1
2
3
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]


  1. Save the changes to the .htaccess file.


This code will check if the request is made over HTTP and then redirect it to the same URL using HTTPS. The [L,R=301] flag at the end of the RewriteRule line indicates that the redirect is a permanent redirect.


After making these changes, all HTTP requests to your CodeIgniter application will automatically be redirected to HTTPS.