I have a simple web hosting platform . I am hosting a Codeigniter application on /var/www/html meaning this is the file structure :
html
|-application
|---controllers
|---models
|---views
|---config
|-public
|-system
|-index.php
|-.htacess
My .htaccess file looks like this :
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
In my config.php file I have default root view controller as :
$config['base_url'] = 'http://www.example.com/';
While in my routes.php file , I have
$route['default_controller'] = "home"
So, naturally when I open www.mysite.com in my browser I get home/index automatically. But when I try any other URL like
www.example.com/home
www.example.com/home/index
www.example.com/admin
I get a 404 error. This is also noticeable that this folder was working perfectly on my local machine and one other remote server that I tried.
To be more precise, when I try www.example.com/home I get this error
Not Found
The requested URL /home was not found on this server.
My home controller looks like this .
class Home extends CI_Controller{
public function __construct() {
parent::__construct();
}
public function index(){
$this->load->view('home_view');
}
public function someFunction(){
echo 'In some function';
}
}
I dont if that helps but adding index.php to the URLs seems to open up the pages as expected. So
www.example.com/controller/function (DOES NOT WORK)
www.example.com/index.php/controller/function (WORKS)
Any help please?
You need to specify the action for different urls in the route file. Like for site.com/search, add this before $route['default_controller'] = "home",
$route['search'] = "home/search"
What this means is, you will create a function search in your home controller which will load the view files for specified url.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.