.htaccess issues: No input file specified
When deploying CodeIgniter (or similar MVC frameworks) to a shared Linux hosting environment, a common stumbling block is the "No input file specified" error paired with a 404 status code. This specific combination usually indicates that Apache's mod_rewrite module has successfully intercepted the request but failed to map it to an existing physical file or directory.
The scenario often arises when moving from a local Windows X64 development setup to a remote Linux server running PHP in CGI/FastCGI mode. While the logic of your .htaccess file might be sound, the environment's configuration dictates whether that logic executes correctly.
The Root Cause: Mod_Rewrite and Directory Handling
In your local environment, Apache serves the request successfully. However, on the remote server, the error "No input file specified" suggests that the RewriteRule is attempting to serve a file path (/index.php/$1) that the web server believes does not exist or cannot be accessed.
The most frequent culprit in this specific configuration is how Apache handles trailing slashes and directory existence checks during rewrite operations. When a request like /something/ hits your server, the RewriteCond excludes standard assets (like CSS or JS), but the rule attempts to redirect everything else to /index.php/something/.
If mod_rewrite is configured with FollowSymLinks Off or if the directory containing index.php is not treated as a valid directory for rewriting, Apache may refuse to serve the file if it perceives the path as pointing to a folder rather than a file. This is particularly sensitive on Linux shared hosting where permission structures and default configurations differ significantly from local Windows setups.
Diagnosing the Rewrite Logic
Your current rule looks like this:
RewriteEngine on
RewriteCond $1 !^(index\.php|css|gfx|js|swf|robots\.txt|favicon\.ico)
RewriteRule ^(.*)$ /index.php/$1 [L]
The RewriteCond checks the captured group $1, but there is a subtle logical gap here. If the URL is /something/, the capture group includes the trailing slash. When you append this to index.php, you get index.php/something/.
If your index.php expects the segment after the dot without a trailing slash (a common pattern in CodeIgniter where the framework parses the URI), passing a trailing slash can sometimes confuse the routing logic or cause Apache to treat the final path as a directory request that requires an internal index file, which might not be found if the rewrite isn't terminating correctly.
The Query String Alternative and Loop Risks
You noted that changing the destination to /index.php?$1 creates an infinite loop. This happens because ? discards the query string but does not handle the path segments in the same way for some frameworks, or it causes the rewrite engine to re-evaluate the URL incorrectly if the framework's internal routing expects a specific URI structure.
However, the critical distinction is that RewriteRule ^(.*)$ /index.php/$1 is attempting to pass the path to the script. If Apache returns "No input file specified," it implies the physical path /index.php/something/ was checked and failed. This often happens if the server is configured to serve directories directly, or if mod_rewrite is not passing the request to FastCGI correctly for that specific URI pattern.
The Fix: Ensuring RewritePasses
The solution often lies in ensuring Apache doesn't try to serve a directory index before rewriting takes place, or by explicitly handling the trailing slash behavior. If you are on a shared host with limited control over the global httpd.conf, you must rely on your .htaccess to be robust.
One effective approach is to ensure that the rewrite rule targets the file strictly and prevents Apache from looking for an index file within a directory context if it thinks one exists. You can try adding [QSA] to preserve query strings, though in this specific case, you are rewriting the path itself.
More importantly, check if your hosting provider has mod_rewrite enabled globally. Sometimes, even if Update 1 suggests it is "installed and on," specific modules like rewrite might be disabled for certain VirtualHosts or user directories on Linux shared hosts.
If the issue persists, try simplifying the condition to ensure no directory traversal issues occur:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
This explicitly checks if the requested filename is not a file (!-f) and not a directory (!-d). By failing these checks, you ensure that Apache does not attempt to serve a static file or directory index before passing the request to index.php. This prevents the "No input file specified" error by forcing the framework to handle all routing logic.
For CodeIgniter specifically, ensure your config/routes.php is configured to accept the trailing slash if your URLs are generated with one, or configure Apache to strip trailing slashes globally if they cause routing ambiguities.