[eluser]Nalorin[/eluser]
Hi All,
I solved the problem below by renaming my "Home" controller to "Site", but I am still curious what the REAL problem is. My guess is just that GoDaddy.com's hosting is stupid...
~~~~~~ All of the following was written before I resolved the problem. See end of post for more info ~~~~~~
I've got a very strange behavioural problem with CodeIgniter on my website.
With my DNS pointed to my development server, everything worked as intended.
When I uploaded to the production server, and updated the DNS, I expected a few snags but nothing like this!
Note: Both the development server and the production server are running Linux
The problem I'm having:
My "Home" controller is not working as expected. Let me explain:
D: Development Server (Linux web server in a VM on my home workstation.)
P: Production server hosted by GoDaddy.com
Code:
// D: Works as Intended
// P: Doesn't Work (CodeIgniter 404 - not Apache 404)
www.example.com/home/select_area
// D: Loads Home->index(), passing "select_area" as a variable
// P: Works as the url above is *intended* to work
www.example.com/home/home/select_area
// In Home->index() for "/home/home/select_area",
echo "[".$this->uri->uri_string()."]";
// outputs: [/home/select_area]
// when it should output: [/home/home/select_area]
Any ideas on what could be wrong?
Here comes all the code that I think could possibly be relevant/related to this problem:
Code:
/* in index.php in web root */
// get URL parts and store in global constants, for easy use later on
preg_match('#^(.*\.)*([^.]+)\.([^.]+)\.([^.:]+)(\:8080)?$#', $_SERVER['HTTP_HOST'],$matches);
define('SUBDOMAIN', $matches[2]);
define('DOMAIN', $matches[3]. '.' .$matches[4]);
define('HOST_PORT', (isset($matches[5]) ? $matches[5] : ''));
define('HOST_ADDR', SUBDOMAIN.'.'.DOMAIN);
define('SITE_DIR', '/my/hosted/site/dir/html');
/* in .htaccess in web root */
addhandler x-httpd-php5 .html
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php/$1 [NE,L]
/* in config.php */
if (HOST_ADDR.HOST_PORT != $_SERVER['HTTP_HOST']) {
header('HTTP/1.1 302 See Other');
header('Location: http://'.HOST_ADDR.HOST_PORT);
exit();
}
$config['base_url'] = 'http://'.HOST_ADDR.HOST_PORT;
$config['index_page'] = "";
$config['uri_protocol'] = "REQUEST_URI"; // only option that works on production server
$config['url_suffix'] = "/";
/* in routes.php */
$route['default_controller'] = "home"; // problem remains, even if changed to "books"
application/libraries/MY_Controller.php:
Code:
class MY_Controller extends Controller
{
protected $data;
function MY_Controller()
{
parent::Controller();
$this->data['debug'] = 0;
$this->data['content'] = 'home';
$this->data['login_data'] = $this->session->userdata('login_data');
if ( ! $this->session->userdata('page_limit')) $this->session->userdata('page_limit',20);
// if city exists in the areas table, proceed with loading page
if ($this->data['city'] = $this->area_model->get_city(SUBDOMAIN)) return;
// if uri_string starts with /home/select_area, proceed with loading page
if (strpos($this->uri->uri_string(), '/home/select_area') === 0) return;
// otherwise, check if session contains last selected city
if ($this->session->userdata('subdomain'))
{
// if so, redirect using that city
redirect('http://'.$this->session->userdata('subdomain').'.'.DOMAIN.HOST_PORT);
}
// if we got this far, no valid area was found, so redirect to area selection page
//redirect('/home/select_area');
}
}
application/controllers/home.php:
Code:
class Home extends MY_Controller
{
function index()
{
$this->load->view('coming_soon');
}
function select_area()
{
$args = $this->uri->segment_array();
if (isset($args[3]) && trim($args[3]) != '')
{
$d = array('subdomain' => $args[3]);
if ($this->area_model->get_city($d['subdomain']))
{
$this->session->unset_userdata('subdomain');
$this->session->set_userdata($d);
redirect("http://{$d['subdomain']}.".DOMAIN.HOST_PORT);
}
}
$areas = $this->area_model->get_area_array();
$this->data['areas'] = $areas;
$this->data['page_title'] = 'Select Your Area';
$this->data['content'] = 'area_select';
$this->load->view('includes/template',$this->data);
}
}
The page is behaving kinda like there's a rewrite rule like this:
Code:
RewriteRule ^/home(.*)$ www.example.com/$1 [L]
Some More Information About The Problem
Every controller (except Home) works fine using /controller/method/...
EVERY controller works using/
home/controller/method/...
~~~~~~ After changing "Home" controller to "Site": ~~~~~~
EVERY controller works as intended as /controller/method
What do you think? Is this just GoDaddy being stupid, or is this a bug in CodeIgniter? Has anyone else had a similar problem?
My project doesn't require the default controller to be named "Home", so I am now posting this for posterity - so if someone else has a similar problem, they will see this solution
Please post if you spot a problem that I missed in the code above.
Cheers