Fixing No input file specified error in CodeIgniter 4

Fixing No input file specified error in CodeIgniter 4

Created:29 Jul 2023 17:05:58 , in  Web development

For some time there seems to be confussion regarding how to remove index.php file from URLs a CodeIgniter 4 PHP framework based application receives as its input without breaking functionality the application provides through controllers. Setting value of indexPage to an empty string in app/Config/App.php file is not enough to achieve this effect. The trick lies in modifying in a particular way .htaccess file found in public/ directory of the framework. If this bit is skipped or done wrong, the change will result in No input file specified error.

I have seen quite a few versions of how to modify the .htaccess file to get rid of the error. Solutinos one can find online, as it turns out, have come quite close to solving the issue for me, but not quite. In particular most of them seemed flawed or not worked at all when extra redirections were added to incoming URLs in the .htaccess file or resulted in weird looking URLs with needless segments and / or question marks.

Steps to fix No input file specified error

Below is my own solution to the problem. It is almost entirely based on the original code provided by the framework.

In order to fix No input file specified error in CodeIgniter 4, first open app/Config/App.php, and set indexPage variable to an empty string, as follows:

public $indexPage = '';

Once done, save the file and close it.

Then, open file public/.htaccess and modify redirection rule responsible for catching request for non-existent files and directories on the operating system. Those should be made available and handled by the framework. The new code (the only change occurs in the line #3) should look as follows:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\s\S]*)$ index.php?$1 [L,QSA]

Save the .htaccess file and refresh browser page which showed No input error occured earlier. The error should be gone and all the URLs and redirections you might have added in your .htaccess should work correctly now.

Tags:  Apache ,  CodeIgniter ,  php 

Author, Copyright and citation


Sylwester Wojnowski

Author of the this article - Sylwester Wojnowski - is a sWWW web developer. He has been writing computer code for the websites and web applications since 1998.


©Copyright, 2023 Sylwester Wojnowski. This article may not be reproduced or published as a whole or in parts without permission from the author. If you share it, please give author credit and do not remove embedded links.

Computer code, if present in the article, is excluded from the above and licensed under GPLv3.


Cite this article as:

Wojnowski, Sylwester. "Fixing No input file specified error in CodeIgniter 4." From sWWW - Code For The Web .

Add Comment

Allowed BB Code - style tags: [b][/b], [i][/i], [code=text][/code],[code=javascript][/code],[code=php][/code],[code=bash][/code],[code=css][/code],[code=html][/code]

I constent to processing my data given through this form for purposes of a reply by the administrator of this website.

Recent Comments

Nobody has commented on this post yet. Be first!