Codeigniter 3.0.4 with 404 Page Not Found Error on my server

倖福魔咒の 提交于 2019-12-10 19:27:10

问题


I am new to the codeigniter. After developing a web app on my localhost .So i uploaded my site on server and then i imported my database. after that i have changed the settings of database in database.php file .. and also i changed the base url in config.php file.

I am getting a 404 Page Not Found. The page you requested was not found. I dont know what is going wrong ..i have searched a lot but nothing helps. and my .htaccess file is empty ..means there is not a single line in it. and one more thing is that i purchase this from godaddy hosting may be helpfull.

my routes.php

$route['default_controller'] = '';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;

my controller doctorscont.php

<?php defined('BASEPATH') OR exit('No direct script access allowed');

class Doctorscont extends CI_Controller {

   public function index() { 
         here is my code.....  */
   }
}

and my config > config.php

$config['base_url'] = ''; 
$config['index_page'] = 'index.php';

[1]:


回答1:


You have to define doctorscont's route in routes.php.

Please add this line at the end of routes.php then visit

$route['doctorscont'] = 'Doctorscont';

If you still get 404 error, please try If it opens, you may want to remove index.php on URL. For this task, visit CodeIgniter URLs Guide

Edit:

Create a .htaccess file under your root (same folder with system and application) with the content below:

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

Than open config.php and edit this line:

$config['index_page'] = 'index.php';

to this:

$config['index_page'] = '';

Now you can get what you want.




回答2:


In version 3+ the filenames must contain the first letter of each file as upper case. It will work in lowercase in your localhost environment but not on server.

Rename the file to 'Doctorscont.php' and you can use the class names as lowercase.

class Doctorscont extends CI_Controller

Edit: http://www.codeigniter.com/user_guide/general/controllers.html#let-s-try-it-hello-world




回答3:


It seems you have not made some changes at apache2 config level please do below changes.

1)sudo a2enmod rewrite

2)gedit /etc/apache2/apache2.conf

3)add below to end of your conf file

<Directory /var/www/html/>
	AllowOverride All
</Directory>

4) Restart apache2 service by below command. service apache2 restart

Best of luck.



来源:https://stackoverflow.com/questions/36504909/codeigniter-3-0-4-with-404-page-not-found-error-on-my-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!