Author Topic: force 'https' with .htaccess and codeigniter on godaddy  (Read 1986 times)

0 Members and 1 Guest are viewing this topic.

Offline boo_lollyTopic starter

  • Devotee
  • Posts: 1,171
  • Gender: Male
  • dirka dirka dirka
    • View Profile
force 'https' with .htaccess and codeigniter on godaddy
« on: July 22, 2010, 02:04:47 AM »
As the title indicates, I'm looking for all the required config variable settings, htaccess conditions and rewrites, etc. Basically, I'm looking for all opinions and examples because I'm almost positive I'll miss something the first time. So far, I've reviewed and slightly understood the validity of the following solutions:

http://codeigniter.com/forums/viewthread/86113/
http://stackoverflow.com/questions/1818869/htaccess-https-to-http

I'm not sure which applies to me, since several options are available. But the kicker is that it's hosted on a client's GoDaddy shared hosting account, and for some reason, "index.php" in the url doesn't work... it MUST be "index.php?" in the url, otherwise it just brings up a "No input file specified" error. It's BS. Anyway can I get some assistance here? Thanks in advance.

Offline petroz

  • Enthusiast
  • Posts: 178
    • View Profile
Re: force 'https' with .htaccess and codeigniter on godaddy
« Reply #1 on: July 29, 2010, 06:47:37 PM »
Show us your httaccess file.

Offline sKunKbad

  • Devotee
  • Posts: 1,477
  • Gender: Male
    • View Profile
    • Brian's Web Design - Temecula
Re: force 'https' with .htaccess and codeigniter on godaddy
« Reply #2 on: July 29, 2010, 09:57:39 PM »
1) Godaddy does offer a refund if you cancel. This is your smartest move, but I understand that it might be somebody elses website you are working on.

2) I normally force HTTPS inside a controller. It would be a rare situation that you would want to force HTTPS for an entire site, but in that case, you could just extend the Controller class with a MY_Controller class. Then you would create a constructor that checks if HTTPS is on, and if not redirect to the equivalent HTTPS page. For an example of forcing HTTPS inside an individual controller:

Code: [Select]
public function __construct()
{
parent::__construct();

// force SSL is available
        // USE_SSL is defined in a hook - 1 is on and 0 is off
if(USE_SSL != 0 && !isset($_SERVER['HTTPS']))
{
$this->load->helper('string');
                // secure_base_url() and url_suffix() come from an extension of the url helper.
header("Location: " . secure_base_url() . trim_slashes( $this->uri->uri_string() ) . url_suffix(), TRUE, 301);
exit;
}
}


MY_url_helper.php:

Code: [Select]
<?php

/*
 * Since trying to access a secure URL can result in errors,
 * this function only creates a secure URL if the my_site_definitions_hook
 * has the setting for USE_SSL set to 1.
 */

function secure_base_url()
{
$CI get_instance();
$url $CI->config->slash_item('base_url');
if(USE_SSL === 1)
{
$url substr($url04).'s'.substr($url4);
}
return $url;
}

/*
 * This function checks if SSL is on for the current request,
 * and if it is, it makes a secure URL. This can be used to 
 * load resources like stylesheets, images, or javascript
 * in a way that won't cause a partially secure warning in the browser.
 */

function if_secure_base_url()
{
$CI get_instance();
$url $CI->config->slash_item('base_url');
if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on')
{
$url substr($url04).'s'.substr($url4);
}
return $url;
}

/*
 * This current_url function has been overridden because
 * the CI version doesn't allow for secure URLs.
 */

function current_url()
{
$CI get_instance();
$url $CI->config->site_url($CI->uri->uri_string());
if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on')
{
$url substr($url04).'s'.substr($url4);
}
return $url;
}

/*
 * This function allows for a more convenient way to 
 * create dynamic URLs that will have the appropriate
 * URL suffix, as specified in the main config file.
 */

function url_suffix()
{
$CI get_instance();
return $CI->config->item('url_suffix');
}

/* End of file MY_url_helper.php */
/* Location: /application/helpers/MY_url_helper.php */

Brian's Web Design - Temecula

Freedom is only available through death.