PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, February 8, 2022

[FIXED] CodeIgniter on localhost : Too many redirects

 February 08, 2022     codeigniter, php, redirect     No comments   

Issue

For testing purpose, I copied all the code and DB records from our live server to a local server.

I edited the following files :

/application/config/config.php (I also edited the DB record)

//$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'] = '**************';

But when I open a web browser I have to following error :

Firefox : The page is not well redirected

Chrome : ERR_TOO_MANY_REDIRECTS

I already tried to change this in /application/config/config.php

$config['uri_protocol'] = 'AUTO';

With all others values but none of them worked.

I also tried to delete my .htaccess without success.

.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

The live server is running without errors with the exactly same code. I do not really know how to proceed... I never used CodeIgniter before, I may need a particular PHP extension enabled ?


Solution

Finally I had to write this in my .htacces

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

in the /application/config/config.php

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

And in the database : http://www.my-site.local (without the trailing /)



Answered By - Atnaize
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing