Php localhost上的CodeIgniter:重定向太多

Php localhost上的CodeIgniter:重定向太多,php,codeigniter,redirect,Php,Codeigniter,Redirect,出于测试目的,我将所有代码和数据库记录从实时服务器复制到本地服务器 我编辑了以下文件: /application/config/config.php(我还编辑了数据库记录) index.php //define('ENVIRONMENT', 'production'); define('ENVIRONMENT', 'development'); $db['default']['hostname'] = 'localhost'; $db['default']['username'] = 'tes

出于测试目的,我将所有代码和数据库记录从实时服务器复制到本地服务器

我编辑了以下文件:

/application/config/config.php(我还编辑了数据库记录)

index.php

//define('ENVIRONMENT', 'production');
define('ENVIRONMENT', 'development');
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'test_localhost';
$db['default']['password'] = '**************';
$config['uri_protocol'] = 'AUTO';
$config['base_url'] = 'http://www.my-site.local/'; //Don't forget the final '/'
/application/config/database.php

//define('ENVIRONMENT', 'production');
define('ENVIRONMENT', 'development');
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'test_localhost';
$db['default']['password'] = '**************';
$config['uri_protocol'] = 'AUTO';
$config['base_url'] = 'http://www.my-site.local/'; //Don't forget the final '/'
但是,当我打开web浏览器时,我必须注意以下错误:

Firefox:
页面重定向不好

Chrome:
ERR\u-TOO\u-MANY\u重定向

我已经尝试在/application/config/config.php中更改此设置

//define('ENVIRONMENT', 'production');
define('ENVIRONMENT', 'development');
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'test_localhost';
$db['default']['password'] = '**************';
$config['uri_protocol'] = 'AUTO';
$config['base_url'] = 'http://www.my-site.local/'; //Don't forget the final '/'
与所有其他价值观,但没有一个工作

我还试图删除我的.htaccess,但没有成功

.htaccess

<IfModule mod_rewrite.c>
    RewriteEngine on

    RewriteBase /

    RewriteCond $1 !^(themes)

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d

    RewriteCond $1 !^(index\.php|assets|static|img|css|js|map|favicon\.ico)
    RewriteRule ^(.*)$ ./index.php?/$1 [L,QSA]
    RewriteRule ^sitemap\.xml$ ./index.php?/$1 [L,QSA]
    RewriteRule ^robots\.txt$ ./index.php?/$1 [L,QSA]

</IfModule>

<IfModule mod_deflate.c>
    <filesMatch "\.(js|css|png)$">
        SetOutputFilter DEFLATE
    </filesMatch>
</IfModule>

AddOutputFilterByType DEFLATE text/ico text/html text/plain text/xml text/css application/javascript application/x-javascript application/x-httpd-php application/rss+xml application/atom_xml text/javascript

重新启动发动机
重写基/
1美元^(主题)
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
1美元^(索引\.php | assets | static | img | css | js | map | favicon \.ico)
重写规则^(.*)$./index.php?/$1[L,QSA]
重写规则^sitemap\.xml$./index.php?/$1[L,QSA]
重写规则^robots\.txt$./index.php?/$1[L,QSA]
SetOutputFilter放气
AddOutputFilterByType DEFLATE text/ico text/html text/plain text/xml text/css应用程序/javascript应用程序/x-javascript应用程序/x-httpd-php应用程序/rss+xml应用程序/atom_xml text/javascript
使用完全相同的代码运行live server时未出现错误。 我真的不知道如何继续。。。
我以前从没用过CodeIgniter,我可能需要启用一个特定的PHP扩展?

如果您在构造函数中使用了重定向,而不是删除它,我会遇到同样的问题,但最后得出结论,我在构造函数中使用了登录会话重定向。

如果您在构造函数中使用了重定向,而不是删除它,我会遇到同样的问题,但最后得出结论,我使用了重定向在登录会话的构造函数中

我在检查项目会话数组变量时遇到了相同的问题,该变量用于检查有效用户,该变量在此会话数组中不存在,这就是导致问题的原因(重定向过多)。检查它是您的会话数组还是其他变量。
可能对您有帮助。

我在检查项目会话数组变量时遇到了相同的问题,该变量用于检查有效用户,该变量在此会话数组中不存在,这就是问题的原因(重定向过多)。检查它是您的会话数组还是其他变量。
也许对你有帮助。最后,我不得不在.htacces中写下这篇文章

RewriteEngine on
RewriteCond $1 !^(index\.php|public|\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1
/application/config/config.php中

//define('ENVIRONMENT', 'production');
define('ENVIRONMENT', 'development');
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'test_localhost';
$db['default']['password'] = '**************';
$config['uri_protocol'] = 'AUTO';
$config['base_url'] = 'http://www.my-site.local/'; //Don't forget the final '/'

在数据库中:
http://www.my-site.local
(没有尾随的
/

最后,我不得不在.htacces中写下这个

RewriteEngine on
RewriteCond $1 !^(index\.php|public|\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1
/application/config/config.php中

//define('ENVIRONMENT', 'production');
define('ENVIRONMENT', 'development');
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'test_localhost';
$db['default']['password'] = '**************';
$config['uri_protocol'] = 'AUTO';
$config['base_url'] = 'http://www.my-site.local/'; //Don't forget the final '/'

在数据库中:
http://www.my-site.local
(不带尾随的
/

此代码看起来不错。可能是您在重定向时在控制器中犯了任何逻辑错误,也可能是它创建了一个循环。一旦我面对同样的问题,在我的例子中,当一个用户试图在没有登录的情况下访问仪表板时,我正在重定向到登录页面,而一个登录的用户,即使他/她试图访问登录页面,我也在尝试重定向到仪表板。@AniketSingh是否知道codeIgniter中首先使用了哪个控制器?打开文件
application/config/routes.php
,然后搜索行
$route['default_controller']='login'在我的情况下,默认控制器是
登录
。每当你点击你的基本网址(');它将执行默认控制器的构造函数的代码,然后执行同一控制器的索引函数的代码。可能是您在重定向时在控制器中犯了任何逻辑错误,也可能是它创建了一个循环。一旦我面对同样的问题,在我的例子中,当一个用户试图在没有登录的情况下访问仪表板时,我正在重定向到登录页面,而一个登录的用户,即使他/她试图访问登录页面,我也在尝试重定向到仪表板。@AniketSingh是否知道codeIgniter中首先使用了哪个控制器?打开文件
application/config/routes.php
,然后搜索行
$route['default_controller']='login'在我的情况下,默认控制器是
登录
。每当你点击你的基本网址(');它将执行默认控制器的构造函数的代码,然后执行同一控制器的索引函数的代码。