how to configure config.php in codeigniter project to redirect to index.php after login

169 Views Asked by At

I had a CodeIgniter project going on before I formatted my PC. After formatting my computer, I configured my project again with Nginx virtual blocks on Ubuntu, but I can only access the login page of the project. after logging in. nginix throws a 404 Not Found error.

my config.php is

if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') {

    $ht = "https://";
} else {
    $ht = "http://";
}
$config['base_url'] = $ht.$_SERVER['HTTP_HOST'];
$config['base_url'] .= preg_replace('@/+$@','',dirname($_SERVER['SCRIPT_NAME'])).'/';
 
**and my virtual host config for the project in nginix is** 

server {
        listen 80;
        listen [::]:80;

        root /var/www/hrms.fs/html;
        index index.php index.html index.htm index.nginx-debian.html;

        server_name hrms.fs;

        location / {
               try_files $uri $uri/ =404;
        }
        
        
        
            index index.php index.html index.htm;

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass unix:/run/php/php8.2-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

}

How can I fix the 404 not found error after login nginx in the Codeigniter project

1

There are 1 best solutions below

0
Mitali Patel On

Please try this following codes. i hope to solve your problem

config/constants.php

define('base_url','http://'.$_SERVER['HTTP_HOST'].str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME'])); define('base_assets', base_url.'assets/');

config/config.php

$config['base_url'] = base_url; $config['base_assets'] = base_assets;

Add .htaccess file

RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
AddDefaultCharset utf-8