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

有帮助吗?

解决方案

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!

其他提示

My .htaccess looks like this:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]

My routes.php looks like this:

$route["default_controller"] = "welcome";
$route["404_override"] = "";

My controller is in this path:

/codeigniter/2.1.4/application/controllers/Welcome.php

I am no .htaccess wiz but can you try making yours match mine?

Update:

Can you take .htacess completely out of the equation for a minute (either by moving, renaming, or deleting the contents of the file) and try visiting these URLs?

http://www.your-website.com/index.php

or

http://www.your-website.com/index.php/welcome

or

http://www.your-website.com/index.php/welcome/index

I have solved this issue by setting the value of "$config['sess_encrypt_cookie']" to "TRUE" In my case it’s due to sanitizing of cookie values by security class. But Encryption of cookie data solves the problem.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top