My Cart 0

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

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(shakzee.com) and you want to redirect from shakzee.com to www.shakzee.com 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 in 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 .htaceess file in the root folder and copy this code in the file.

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

If you want to redirect your request form 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 ^ https://www.yourDomainName.com%{REQUEST_URI} [R=301,L,NE]
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /index\.php(/[^\ ]*)?\ HTTP/
RewriteRule ^index\.php(/(.*))?$ yourDomainName.com/$2 [R=301,L]

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

shakzee
administrator
I have been in the web design and development sector for over 5 years. I always provide high-quality courses which can be useful and practical for students, I am working for my community since 6 years and I have created thousands of lectures related to web development and different programming languages. Before selecting any course please make sure the language of the course because I am providing many courses in URDU and English language.

Leave a Reply

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

WhatsApp chat