Home > Software design >  Remove index.php in Codeigniter 3 in Url
Remove index.php in Codeigniter 3 in Url

Time:12-16

My site now can only access default controller which is home, and when I want to go to signin page it returns 404 Not Found.

Usually I just have to configure code block nginx and I think the configuration is correct, I also restart the nginx service and there is no problem.

But website still can't access signin page without index.php in the url (https://example.com/index.php?/signin)

Here's my configuration :

server {
    listen      ip:80;
    server_name example.com www.example.com;
    root        /home/admin/web/example.com/public_html;
    index       index.php index.html index.htm;
    access_log  /var/log/nginx/domains/example.com.log combined;
    access_log  /var/log/nginx/domains/example.com.bytes bytes;
    error_log   /var/log/nginx/domains/example.com.error.log error;

    location / {
        try_files $uri $uri/ /index.php?$query_string;

        location ~* ^. \.(jpeg|jpg|png|gif|bmp|ico|svg|css|js)$ {
            expires     max;
        }

        location ~ [^/]\.php(/|$) {
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            if (!-f $document_root$fastcgi_script_name) {
                return  404;
            }

            fastcgi_pass    127.0.0.1:9001;
            fastcgi_index   index.php;
            include         /etc/nginx/fastcgi_params;
        }
    }

    error_page  403 /error/404.html;
    error_page  404 /error/404.html;
    error_page  500 502 503 504 /error/50x.html;

    location /error/ {
        alias   /home/admin/web/example.com/document_errors/;
    }

    location ~* "/\.(htaccess|htpasswd)$" {
        deny    all;
        return  404;
    }

    location /vstats/ {
        alias   /home/admin/web/example.com/stats/;
        include /home/admin/conf/web/example.com.auth*;
   }

    include     /etc/nginx/conf.d/example.inc*;
    include     /etc/nginx/conf.d/example.inc*;
    include     /etc/nginx/conf.d/webmail.inc*;

    include     /home/admin/conf/web/nginx.example.com.conf*;
}

CodePudding user response:

It was TSL Issue, I set $config['base_url'] into https which it's should be http Sorry, my mistake

CodePudding user response:

Mostly, this error is brought by lack of an .htaccess file in the root directory of your folder. So be sure to create a .htaccess file in the root directory and add the following content to it

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</filesMatch>

What it does it renames the URL and removes the need to add index.php on your URLs.

  • Related