0

SCENERIO: Recently I migrated CodeIgniter from 2.4 to 3.1.9 along with PHP from 5.2 to 7.2. Also, created a new httpd.conf file in apache. When I go to the site's URL, it loads the default page fine and I can browse to default or root pages without any issues. There are multiple sub-domains that are mapped in routes.php to the main httpd root directory /var/www/html. These sub-domains have a symbolic link to /var/www/html, and within assets folder are the customization files for each sub-domains.

Root HTTPD directory "/var/www/html" structure

application assets
test1 -> /var/www/html    
test2 -> /var/www/html
index.php
system

URL is set as follows in config.php.

$config['base_url'] = 'https://example.com/';

Below is my entry in routes.php:

$route['default_controller'] = "home";
$route['404_override'] = '';

$route['home'] = "home";
$route['select-product'] = "home/select-product";
$route['test1/select-product'] = "home/select-product";
$route['test2/select-product'] = "home/select-product";

Please check the below image for httpd directory config:

enter image description here

PROBLEM: When I browse to https://example.com/ it loads everything correctly. When I go to https://example.com/test1 ==> First page loads correctly. But when I press next, the second page defaults back to 'https://example.com/';. Somehow, it looses /test1 from the browser.

Not sure if this is caused by CodeIgniter URL routing issue or something to do with httpd.conf file of Apache. The same "routes.php" file was working fine on the old server.

The routing/pagination seems to have broken after I set $config['base_url'] = 'https://example.com/';. If left empty, it takes a while for the site to load, and when it does the forms and images are not loaded correctly.

I have spent lots of hours trying to figure out the problem. I am hoping someone genius out there will be able to show be in the right direction.

Thank you.

BBT
  • 211
  • 1
  • 3
  • 8
  • Hi all, What I've discovered might give us some clues in regards to what is happening... So, when I browse the web-page using the private IP it works fine. When it is loaded with public IP, the home page loads, but the URL address on the next page changes to "Private IP" and it fails to load the page. This behaviour is observed when $config['base_url'] = ''; is left empty and $config['uri_protocol'] = 'ANY OPTION WORKS'; – BBT Jul 05 '18 at 04:09

1 Answers1

0

I had this problem when I upgraded to PHP 7.2, the best solution is ,

for things to work in CI with PHP7.2,

  1. Find and comment out(or remove) the following code from sessions.php (system/libraries/session/session.php) and place it in your index.php at the top.

    session_start(); 
    ini_set('session.use_trans_sid', 0); 
    ini_set('session.use_strict_mode', 1); 
    ini_set('session.use_cookies', 1); 
    ini_set('session.use_only_cookies', 1); 
    ini_set('session.hash_function', 1); ini_set('session.hash_bits_per_character',4);
    
  2. and for .htaccess, use this

    DirectoryIndex index.php
    RewriteEngine on
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond $1 !^(index\.php|.well-known|images|robots\.txt)
    RewriteRule ^(.*)$ index.php?/$1
    
  3. set your uri protocol to AUTO

    $config['uri_protocol'] = 'AUTO';
    $config['index_page'] = '';
    
Arun Panneerselvam
  • 2,263
  • 1
  • 17
  • 24