Welcome Guest, Not a member yet? Register   Sign In
Codeigniter HTTPS (SSL) What is the "Best Practice"?
#1

I have a Codeigniter application which was developed and tested on the normal http. Now the Apache server has been configured in such a way that all of the pages are stored in a single folder which is SSL enabled. The SSL certificate is in place. When I browse to the website using "https://www" then it redirects to "http://www". NOTE : I do not need to load specific pages using SSL. I just need all pages to show as HTTPS.

I have tried the proposed solutions suggested on Stack Overflow including :

1. Modifying the .htaccess file to force HTTPS

2. Setting the $config['base_url'] = "https://www.yoursite.com/";

When I tried the above method in tandem then Firefox gave the following error : "The page isn't redirecting properly. Firefox has detected that the server is redirecting the request for this address in a way that will never complete."

Many Stack Overflow contributors suggest that this should be handled by Apache only. That makes sense to me but forcing HTTPS via .htaccess gives the same error.

Is there a simple "best practice" way to do this without hooks and SSL Helpers, etc?
Reply
#2

(This post was last modified: 01-25-2016, 08:53 AM by skunkbad.)

In my own websites, I have used the following for .htaccess:


Code:
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://example.com/$1 [R,L]

You didn't share what you did, so it's impossible to know.

It does look like you've set the base_url correctly.

You might check the security cert and make sure www is covered, but I don't think that's your problem.
Reply
#3

Hi ~ here is the .htaccess code I used :

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

And the */application/config/config.php file includes :

$config['base_url'] = "";
Reply
#4

(This post was last modified: 04-29-2019, 01:08 PM by ciadmin.)

redirect to https url in codeigniter using hooks is a good method rather than htaccess
i use this tuts *Redacted: no longer working*
Reply
#5

Thanks Suhindra. I did come across this tutorial. I was wondering if you think that there are advantages to using "Hooks" for this purpose?
Reply
#6

(This post was last modified: 01-29-2016, 02:19 PM by mwhitney.)

I have separate conf files in Apache for http and https, with the https conf specifying:

Code:
<VirtualHost *:443>

and including the SSL configuration, but otherwise it's a fairly normal configuration for a CI site.

For some of my sites, the http conf file looks something like this:

Code:
<VirtualHost *:80>
    ServerName my.url.here
    Redirect 301 / https://my.url.here
</VirtualHost>

For other sites, I might have a normal http conf for the port 80 virtual host, or some portions of the site may be redirected to https. In all cases, I set the site's base_url to include the https://, so they end up using https once they click a link on the site, regardless of whether they were redirected in the first place.
Reply
#7

(This post was last modified: 04-29-2019, 01:10 PM by ciadmin. Edit Reason: missed a word )

Hi
I have renewed my SSL certificate with Godaddy, I´ve been instructed to redirect my website to HTTPS by changing the htaccess file.

 <IfModule mod_rewrite.c>

RewriteEngine On

RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ example.com/$1 [L,R=301,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

The website when is redirected to https the website is completely different and not functional.

Could someone help me with this issue please?
Many thanks in advanced
Reply
#8

(This post was last modified: 06-18-2018, 01:11 AM by CINewb.)

(01-29-2016, 02:18 PM)mwhitney Wrote: I have separate conf files in Apache for http and https...

Same here, in my opinion this is Apache's job, not CodeIgniter's. Any method other than a separate virtual host is less efficient (albeit you probably won't notice any difference in terms of performance).
Reply




Theme © iAndrew 2016 - Forum software by © MyBB