【问题标题】:CodeIgniter on localhost : Too many redirects本地主机上的 CodeIgniter:重定向太多
【发布时间】:2016-12-12 12:31:59
【问题描述】:

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

我编辑了以下文件:

/application/config/config.php(我也编辑了DB记录)

//$config['base_url']   = 'https://www.OurWebsite.eu/';
$config['base_url'] = 'http://localhost/test/';

index.php

//define('ENVIRONMENT', 'production');
define('ENVIRONMENT', 'development');

/application/config/database.php

$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'test_localhost';
$db['default']['password'] = '**************';

但是当我打开网络浏览器时,我必须出现以下错误:

火狐:The page is not well redirected

铬:ERR_TOO_MANY_REDIRECTS

我已经尝试在 /application/config/config.php

中更改此设置
$config['uri_protocol'] = 'AUTO';

使用所有其他值,但它们都不起作用。

我也尝试删除我的 .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

实时服务器使用完全相同的代码运行而没有错误。 我真的不知道如何继续...... 我以前从未使用过 CodeIgniter,我可能需要启用特定的 PHP 扩展?

【问题讨论】:

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

标签: php codeigniter redirect


【解决方案1】:

最后我不得不在我的 .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

$config['base_url'] = 'http://www.my-site.local/'; //Don't forget the final '/'

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

【讨论】:

    【解决方案2】:

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

    【讨论】:

      【解决方案3】:

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

      【讨论】:

        【解决方案4】:

        在我的情况下,我在 url 中的一个文件夹名称中有一个空格:http://localhost/some%20folder/admin/

        重命名文件夹以删除空间修复了问题。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2019-07-24
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2017-05-16
          • 2011-01-06
          相关资源
          最近更新 更多