fbpx

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(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
First, let me first introduce myself. 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. Web design and development constantly developing every day with new trends, ideas, and innovations. That’s why nowadays you need to learn and keep yourself up-to-date with everything daily and that’s what I do and that is something that I love because I am so passionate about it! When I have spare time I use to give time to my web development community. Teaching kids, managing online programming groups, attending a conference and making blogs, I like keeping myself up-to-date and engaged in my field always. I have my expertise in (PHP, Codeigniter, Laravel, Bootstrap, WordPress, SQL, Query Optimization, Data Science and Design Patterns). Anyone who wants to learn and know anything about web development and design I am always available for that and would love to help out. I always love to be looking out for new things and that is why I spend a lot of my time learning new techniques and helping other people learn web development and design through various groups and web development tutorials as well as online courses.

Leave a Reply

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

WhatsApp chat