2

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

  1. $config['index_page'] = '';
  2. restart apache2 service: sudo /etc/init.d/apache2 reload
  3. Add below code to /var/www/html/my_ci_site/.htaccess

    RewriteEngine on
    RewriteBase /
    RewriteCond $1 !^(index\.php|static|robots\.txt|favicon\.ico|uploads|googlexxxxxxxx\.html|mobile.html)
    RewriteRule ^(.*)$ index.php/$1 [L]
    
  4. Replace every instance of AllowOverride None to AllowOverride All in /etc/apache2/apache2.conf

  5. Enable rewrite mode: sudo a2enmod rewrite
  6. 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.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Houy Narun
  • 1,557
  • 5
  • 37
  • 86

1 Answers1

1

In Ubuntu You have to do virtual host to working. For this first in /etc/apache2/sites-available create yourproject.conf file(may be you may need root permissions use sudo command)

For this in terminal

 cd /etc/apache2/sites-available

Then

sudo nano yourproject.conf

Copy below content and paste into it

<VirtualHost *:3434>
      ServerName  localhost

      DirectoryIndex index.php
      DocumentRoot /var/www/html/yourprojectfolder

      <Directory "/var/www/html/yourprojectfolder">
      Options All
      AllowOverride All
      Allow from all
      </Directory>

</VirtualHost>

Note:You can use different ports here

Then run

sudo nano /etc/apache2/ports.conf

In this file add line (Do not edit existing ports )

Listen 3434

Then run

sudo a2ensite yourproject.conf sudo a2enmod rewrite

in config.php

$config['base_url'] = 'http://localhost:3434';
$config['uri_protocol']    = 'REQUEST_URI';
$config['index_page'] = '';

Create .htaccess inside yourproject folder with below content

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [L]

Then 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 url

for example http://localhost/homerent/Login is the url using now and After setting up virtual host You can use http://localhost:3434/Login