The last one I follow is here How to remove index.php from codeigniter in UBUNTU [duplicate]
I have one controller that look like this:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Login extends CI_Controller {
public function index()
{
$this->load->view('login.html');
}
}
When I access it by this URL: http://localhost/homerent/Login, I got 404 not found.
I follow from answer above in referent link by
- $config['index_page'] = '';
- restart apache2 service: sudo /etc/init.d/apache2 reload
Add below code to
/var/www/html/my_ci_site/.htaccessRewriteEngine on RewriteBase / RewriteCond $1 !^(index\.php|static|robots\.txt|favicon\.ico|uploads|googlexxxxxxxx\.html|mobile.html) RewriteRule ^(.*)$ index.php/$1 [L]Replace every instance of
AllowOverride NonetoAllowOverride Allin /etc/apache2/apache2.conf- Enable rewrite mode:
sudo a2enmod rewrite - Finally restart apache2 service again.
After all, I access my url again http://localhost/homerent/Login I still get 404 not found.
I have no clue what is wrong with that.
In Ubuntu You have to do virtual host to working. For this first in
/etc/apache2/sites-availablecreateyourproject.conffile(may be you may need root permissions usesudocommand)For this in terminal
Then
sudo nano yourproject.confCopy below content and paste into it
Note:You can use different ports here
Then run
sudo nano /etc/apache2/ports.confIn this file add line (Do not edit existing ports )
Listen 3434Then run
sudo a2ensite yourproject.conf sudo a2enmod rewritein
config.phpCreate .htaccess inside
yourprojectfolder with below contentThen restart apache to take effect the changes
Now you can access your site through the url
http://localhost:3434(This will load the defaulf controller) and no need to add the project folder in the urlfor example
http://localhost/homerent/Loginis the url using now and After setting up virtual host You can usehttp://localhost:3434/Login