
- Views: 4.9K
- Category: Web Development
- Published at: 02 Aug, 2018
- Updated at: 01 Sep, 2023
Redirect from http to https using .htaccess file in codeigniter OR wordpress
Redirect from HTTP to HTTPS using the .htaccess file in Codeigniter
If you have a website with HTTP and have purchased the SSL for your site, it's hard to manage redirection because every request to your site has HTTP before any request, so how can you redirect your every request...?
If you want to add www with every request of your site, for instance, someone accessing your website without www(shekztech.com) and you want to redirect from shekztech.com to www.shekztech.com, how can you do that..?
If you are working on WordPress, you have many options; you can install a plugin like Really Simple SSL. You can find other plugins to redirect.
But why do you need to install a plugin if you have many plugins 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 must be familiar with the .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 the .htaccess file..?
.htaccess is a configuration file used on web servers running the Apache Web Server software.
Now we will add a .htaccess file that redirects your request from HTTP to HTTPS.
Step 1: Create a .htaceess file in the root folder and copy this code into the file.
If you want to redirect your request from HTTP to HTTPS without installing any plugin, 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.
https://www.youtube.com/watch?v=lPl2zmjNpl8
- Tag
- .htaccess file
0 Comment(s)