CodeIgniter: 404 Page Not Found on Live Server
Asked Answered
S

10

39

I have been developing a small web application with CodeIgniter. After testing it out locally I went to put it on my web server to allow a couple other people test out some features. While navigating to the site I get: -

404 Page Not Found error page

When viewing it in my local machine everything loads up and runs perfectly.

This is what I uploaded to the public_html directory:

application directory
system directory
assets directory (my assets for the site)
index.php

All of those are in the public_html directory. Like I said, it does give me CodeIgniters 404 error page, so I do know it is at least seeing CodeIgniter. I also tried changing the $config['base_url'], in the config.php, to my URL. Same error when changing that or leaving it blank. I checked my routes, and all those seem correct. Everything also loads up just fine when navigating to it on my local machine.

I also am not using a .htaccess file at this time

Any suggestions on what I should try?
Thanks a lot!

Slalom answered 25/2, 2015 at 0:46 Comment(1)
you can find your answer from this link #9315816 and #17631169Manno
A
101

You are using MVC with OOPS Concept. So there are some certain rules.

1) Your class name (ie: controller name) should be start with capital Letter.

e.g.: your controller name is 'icecream'. that should be 'Icecream'

In localhost it might not be compulsory, but in server it will check all these rules, else it can't detect the right class name.

Acquah answered 13/5, 2015 at 6:53 Comment(4)
Just a note: the class name and the file name both need to be title case (start with a capital letter). So if the class name is 'Icecream', the file name needs to be 'Icecream.php', otherwise, CodeIgniter will throw a 404 error.Pen
I don't think on server it checks all these rules. It could be due to the simple fact that the server runs Linux which is case sensitive for file names...Sharice
This is the case, also must verity the controller files on the server, Because sometimes even you ftp the file with title case it will not replace properly & better way is first delete the controllers on the server & upload the files with proper file name.Klink
Happened with me. I was using MacOS for development which has a case-insensitive file system by default but the production server was on Linux. Scratched by head for almost a day.Evonevonne
R
18

There are a number of things you can check here. I'll go over each one with you.

1, When moving to a live server from localhost(htdocs) you need to make sure that the version of PHP you are using is supported.

To test this: Create an 'index.php' file and add the below line only.

<?php phpinfo(); ?>

Just press 'Ctrl + F' and search "version". You will find the php version. It may need to be 5.3+ to support features.

2, Check your config/config.php and check your $config['base_url'] and $config['index_page'] screen shot below

enter image description here

I recommend putting site name in the base url example: 'www.site.com/' but remove the index.php for cleaning.

3, MOST LIKELY THE REASON SO START WITH THIS

It most likely is the .htaccess file. Here is mine Made by Elliot Haughton. Put this in your root directory and change line 9 'RewriteBase /' if necessary.


<IfModule mod_rewrite.c>
    RewriteEngine On
    # !IMPORTANT! Set your RewriteBase here and don't forget trailing and leading
    # slashes.
    # If your page resides at
    # http://www.example.com/mypage/test1
    # then use
    # RewriteBase /mypage/test1/
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.
    # Submitted by: ElliotHaughin 
    ErrorDocument 404 /index.php
</IfModule>

If none of the above works, give me a shout back and we'll step through it.

Rhumb answered 25/2, 2015 at 17:59 Comment(5)
Thanks for attempting to help. I have tried all of those suggestions and I am still getting errors. I have tried with the base_url empty, and also tried with it set to my URL.Slalom
Also, when I set the .htaccess file, I no longer get CodeIgniters error page, instead it turns into an internal server error. I have tried everything I could think of for the rewrite base. This site is being uploaded as a subdomain of another site I have if that helps. I have also uploaded another CodeIgniter app as a sub domain that I created couple months ago and it uploaded perfectly and works great. Though when I upload this one the exact same way I get the errors I had been describing....Slalom
I was having troubles to reach to the URL's like: domain/catalog/$1, and those was fixed with the htacces fileTravertine
@Slalom You are getting internal server error because the htaccess file is not ending properly. At the end change <IfModule !mod_rewrite.c> to </IfModule>Idonna
Following are all the possibilities 1-- htaccess 2-- application/config/config.php 3-- Apache2 Allow override for www (sudo a2enmod rewrite) 4-- Camel caseDiphase
I
18

Changing the first letter to uppercase on the file's name and class name works.

file: controllers/Login.php

class: class Login extends CI_Controller { ... }

The file name, as the class name, should starts with capital letter. This rule applys to models too.

https://www.codeigniter.com/user_guide/general/models.html

Incivility answered 15/7, 2015 at 18:17 Comment(0)
U
14

I had the same problem. Changing controlers first letter to uppercase helped.

Unsound answered 12/5, 2015 at 20:31 Comment(0)
F
12

I have solved this problem, please just make few changes

1- all controller class name should start with capital letter. i mean first letter of class should be capital . eg we have controler with class name Pages

so it should be Pages not pages

2- save the controller class Pages as Pages.php not pages.php

so first letter must be capital

same for model, model class first letter should be capital and also save model class as Pages_model.php not page_model.php

hope this will solve ur problem

Furlong answered 22/9, 2015 at 19:23 Comment(1)
after renaming all class files including models and library files i.e only initial letters in Uppercase it starts working. Thanks a lot.Iodide
R
5

I was stuck with this approx a day i just rename filename "Filename" with capital letter and rename the controller class "Classname". and it solved the problem.

**class Myclass extends CI_Controller{}
save file: Myclass.php**

application/config/config.php

$config['base_url'] = '';
Remanent answered 3/11, 2015 at 18:17 Comment(0)
A
3

I am doing it on local and production server this way:


Routes:

$route['default_controller']   = 'Home_controller';

Files' names:

  • in controllers folder: Home_controller.php
  • in models folder: Home_model.php
  • in views folder: Home.php

Home_controller.php:

       class Home_controller extends CI_Controller {

           public function index(){

              //loading Home_model
              $this->load->model('Home_model');

              //get data from DB
              $data['db_data']  = $this->Home_model->getData();

              //pass $data to Home.html
              $this->load->view('Home', $data);
           }
       }

Home_model.php:

       class Home_model extends CI_Model {
       ...
       }

There should be no more problems with cases anymore :)

Affiliate answered 21/9, 2015 at 16:23 Comment(0)
M
1

Try to add following line in root folder index.php after php starts:

ob_start();

This works for me.

Moten answered 13/9, 2018 at 7:47 Comment(0)
S
0

Please check the root/application/core/ folder files whether if you have used any of MY_Loader.php, MY_Parser.php or MY_Router.php files.

If so, please try by removing above files from the folder and check whether that make any difference. In fact, just clean that folder by just keeping the default index.html file.

I have found these files caused the issue to route to the correct Controller's functions.

Hope that helps!

Shupe answered 5/8, 2015 at 16:50 Comment(0)
L
0

Add following line in root folder index.php just after <?php starts:

ob_start();

Laconia answered 2/12, 2023 at 17:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.