Selective 404 error on CodeIgniter installation - php

I copied a fully functional CodeIgniter app into a new server, updated the config.php base url, and setup all database parameters accordingly.
An interesting problem I'm having is that the new install (in new server) returns a 404 for all controllers I try to access. However, when navigating to the base URL, my default controller welcome.php defined in routes.php is rendered fine on the browser.
$route['default_controller'] = "welcome";
This suggests to me that CI is running OK but there may be some other routing issue I'm not figuring out.
My .htaccess is
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
which works fine on the other server.
Any ideas what I'm doing wrong here?

Is your apache directory configuration set to AllowOverride All?

Related

live server shows 404 error, but not on local, codeigniter 3

I have four identical pages that only differs in some identifiers but the logic is very much the same. All of them works on localhost. Three of those pages works okay on live server, but one of them returns a 404 for some reasons I can't understand.
I use XAMPP 3.2.2 and Sublime for developing it on local. I moved it to GoDaddy Deluxe Linux for live. My Codeigniter version is 3.1.10.
I already tried answers from most of the questions on StackOverflow:
All controller and model names' first letters are capitalized in the file name and inside the file.
All of the .htaccess codes on here: https://github.com/tasmanwebsolutions/htaccess_for_codeigniter
I have two .htaccess files, one of them is inside the application folder, and one is outside. I don't know if that's confusing the system? But I have another website on a different hosting that has the same .htaccess files and they're working okay. And anyway, if that's confusing the system, why does it only affect one of the four identical pages?
.htaccess outside application folder
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>
.htaccess inside application folder:
<IfModule authz_core_module>
Require all denied
</IfModule>
<IfModule !authz_core_module>
Deny from all
</IfModule>
All of the controllers of the four files has this up top:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
//session_start(); //we need to call PHP's session object to access it through CI
class Question1 extends CI_Controller
{
and the rest is normal code stuff that are working on three of those four files.
In config. php I have:
$config['uri_protocol'] = 'REQUEST_URI';
and base_url is great.
Models and views are okay, as far as I can see, and the rest of the website is functioning alright with the included .htaccess. My routes are working okay, as well.
I'm so lost right now.
PS. I have a custom 404 page. When I input assessment.com/index.php/question1 it shows that custom 404 page. But when I open assessment.com/question1 it shows codeigniter's own 404 page (and not my custom one, for some reasons). I think that tells something, I just don't know what.
EDIT
Here's my routes.php:
$route['default_controller'] = 'home';
$route['404_override'] = 'Error404';
$route['translate_uri_dashes'] = TRUE;
I opted not to do
$route['question1'] = "Question1";
in routes because it doesn't change anything.
Check your APPLICATION ENVIRONMENT mode. You can find it on your project root_folder/index.php and at line no. 57.
define('ENVIRONMENT', 'production');
Change the ENVIRONMENT mode into the development mode, that is
define('ENVIRONMENT', 'development');
Then refresh your applications again. If you see CodeIgniter default error you can understand your CodeIgniter application are running ok and check out the error.If it doesn't show any error then your .httaccess has any error. I solved it my 404 error with this code, you can check this out.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^asset.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
Answering this for the others who might come across the same problem.
Okay so user Don't Panic suggested I echo just "question x" in the problematic controller, and when I did that, the 404 error went away and it echoed the "question x." So definitely it's my controller that has the problem and not my routine or .htaccess files.
Now this controller is designed in such a way that it calls first an ID from the database before it shows anything. After I echoed "question x" I realized that the ID it is calling from my database has a value of zero. So, unsurprisingly, from the controller's point of view, the page doesn't exist! Hence the 404.
I've fixed it now by updating that table from my database and giving the ID a value it should already have had in the first place.

Routes in Codeigniter not working on different server

Let me inform you this first. This application is working pretty fine on live server currently, however we needed to move it to a different server with a different domain.
Issue is: It gives 404 error on every other page except for index. Loading through index.php works fine.
For an example:
www.test.com/main/login //This gives 404 error
www.test.com/main/index.php/login //This loads fine
Because everything is working fine currently, I made changes only in $config['base_url'] and in database config file. There have been no other changes in any of the files.
Also, this solution provided by somebody in a different questions is already tried out and this doesn't work. Solution is to create .htaccess file with below code & setting $config['index_page']='' :
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Current server is VPS & provider is GoDaddy. New server is Shared hosting and provider is GoDaddy. I'm not getting the root cause of this happening, can somebody point out to the possible solution?
EDIT
I'm attaching a screenshot for an error, it's not typical 404 error page. In case this helps.
For Godaddy, you need to alter this 2 things.
In your .htaccess file, replace
RewriteRule ^(.*)$ index.php/$1 [L]
With the following:
RewriteRule ^(.*)$ index.php?/$1 [L]
Then is your application/config/config.php :
$config['index_page'] = '';
Both this changes should help you resolve your issue.

CodeIgniter upgrade from 2.2.0 to 3.0.x: Only the default controller is loading

I don't usually post messages on the web to get help but I feel that I have tried everything and I am stuck.
I wanted to upgrade CodeIgniter from version 2.2 to version 3.0.3 (I tried v3.0.2 too) and I followed the corresponding guide on codeigniter.com. But now, only the default controller is loaded, no matter the url.
I have searched on the web and I have found out that it could come from:
the htaccess
the application/config/config file
the application/config/routes file
the new Ucfirst rule for the filenames (controllers, models...)
But I still don't have the solution...
The files in "applications/controllers" are all Ucfirst.
Everything was working fine before (with version 2.2), so WAMP should be correctly configured (mod_rewrite enabled etc...). Moreover, I have tried and succesfully loaded a clean instance of CodeIgniter 3.
Models, Controllers and Views are loaded correctly, I can change my default controller and it will load the correct view (with requests done by controllers and models). But it only loads the default controller, no matter what the url is (in the browser). Even if it does not exist, I never have the 404 page. Except if I specify an incorrect "default_controller" (in the file "routes.php").
It has to be a routing issue...
Here is some of the tests I have done:
Table of tests
Here is my htaccess file (I have tried other ones on the web too, the result is the same):
RewriteEngine On
#Checks to see if the user is attempting to access a valid file,
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#Enable access to the images and css folders, and the robots.txt file
RewriteCond $1 !^(index\.php|public|images|robots\.txt|css)
RewriteRule ^(.*)$ index.php/$1 [L]
Here is my "application/config/routes" file:
$route['default_controller'] = 'dashboard';
$route['404_override'] = 'auth/e404';
$route['translate_uri_dashes'] = FALSE;
Any help would be appreciated :-)
Thank you !
SOLUTION
$config['enable_query_strings'] was set to "TRUE" in the file "application/config/config.php". Setting it to "FALSE" solved the issue. So simple...
try putting the index method in the routes, for example instead of this
$route['blog'] = 'blog';
try this
$route['blog'] = 'blog/index';
and if that doesn't work, can you confirm you have set the correct base url in application/config/config.php ?
In codeigniter 3 wamp
I use this htaccess
Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
With your error 404 over ride can not be in sub folder.
Change
$route['404_override'] = 'auth/e404';
To
$route['404_override'] = 'e404';
And on config.php
$config['base_url'] = 'http://localhost/your_project/';
// You can leave base url blank but not recommended because when you try to submit forms make cause issue.
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';

CodeIgniter MY_Controller not working in web server

I extended the CI_Controller and made my own controller to be extended.
Now everything works fine in localhost (xampp) but when I copied the files over to my web server, I get 500 internal server error which is quite useless. Odd to me is the fact, that I get internal server error instead of codeigniter generated error.
Things I have tried so far:
1) tried libraries folder instead of core for MY_Controller
2) I have had problem with server only accepting lowercase file names so I tried my_controller and changing config file prefix, main.php extension and so on.
Both of these seems like useless tries anyways, cause I didn't get error saying it can't be found or something similar.
When I change my main.php controller to extend CI_Controller, everything works fine.
I know I haven't provided much information, but I have no idea what to provide. Again, it works in localhost.
Thanks for any input you might have.
Try changing your config.php to.
$config['index_page'] = '';
and the .htacces of the site to:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/system.*
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?/$1 [L]

Codeigniter can only access default route controller

I suspect this may be a webserver configuration change that has taken place, and my hosting provider hasn't told anyone, but anyway...
I have a Codeigniter instance set up with the following directory structure:
/root
/codeigniter
/app
/sys
/www
/sandbox
/ci
/js
/css
/img
.htaccess
index.php
Therefore in index.php, I have the following variables:
$application_folder = '../../../codeigniter/app';
$system_path = '../../../codeigniter/sys';
These are relative definitions due to it being a shared hosting provider, however it does appear to be working that way so I don't think this is the issue (in WAMP i have those folder paths explicitly defined, e.g. c:/wamp/ci/application)
In config.php, I have the following variables set:
$config['base_url'] = 'http://******.co.uk/sandbox/ci/';
...
$config['index_page'] = '';
...
$config['uri_protocol'] = 'AUTO';
and my .htaccess file in www/sandbox/ci is set like so:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
Up until a few days ago, this all worked fine, however, I replaced a fair few files just before Christmas, and may have accidentally overwritten something without realising it. This setup works fine on my WAMP server, but fails on my live server If I attempt to access any function in any controller that isn't the one defined in routes.php.
My routes.php looks like this:
$route['default_controller'] = "home_controller";
$route['404_override'] = '';
home_controller appears fine, however if I attempt to do something like login (which is processed via a form POST to auth_controller/login), it fails with 404. I do not have any additional functions in home_controller.
I get nothing interesting from setting the logging threshold to 4, and ChromePHP just suggests that it cannot find a path to the controllers.
mod_rewrite seems to be working, because if I add anything plaintext to the .htaccess file, I get a server error 500, and furthermore the index.php rewrite is working. I also have rewrite_short_tags set to TRUE.
I have tried all of the uri_protocol types in the config.php, and none seem to make any difference, so I feel like if it is something i've done, i'm either missing something from routes.php, or something missing from my .htaccess.
Any thoughts would be appreciated. Like I said, this entire setup works on my WAMP server without issue.
I think the problem is in your htaccess. Try this htaccess for a moment..
<IfModule mod_rewrite.c>
RewriteEngine On
# Set the rewritebase to your CI installation folder
RewriteBase /sandbox/ci/
# Send everything to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
I hope this helps you out.

Categories