Search code examples
php.htaccesscodeigniterhttp-redirectcodeigniter-2

PHP - Codeigniter - Redirect Loop


Whenever I visit my website at [website].com the page will continuously redirect until the browser shows This webpage has a redirect loop.

BUT

When I visit [website].com/[controller] then everything works fine.


Not all of this may be relevant but I will list as much information as I can/know.

The default controller in routes.php is welcome

The welcome controller:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Welcome extends CI_Controller
{
    public function index()
    {
        // Testing: Does not reach this die statement
        die('error');
        //$this->load->view('public/welcome');
    }
}

.htaccess file:

RewriteEngine On
RewriteCond $1 !^(index\.php|assets|robots\.txt)
RewriteRule ^(.*)$ index.php?/$1 [L]

Update


This might be an(the) issue but I have the [website].com domain pointing to a sub folder /public_html/[website].com/ where I have my Codeigniter folder structure as well as index.php and .htaccess


Solution

  • So with a little debugging I figured out that it wasn't any .htaccess file that was messing around with redirecting. It was actually the CodeIgniter Framework. And to be more specific, a Hook.

    A problem with the hook made it constantly redirect to [website].com which tried to access the default controller welcome ... and then redirect, so on and so forth.

    Oh, the little things!

    Thanks for everyone's help!