无法从Ubuntu的Codeigniter中删除index.php

无法从Ubuntu的Codeigniter中删除index.php,php,apache,codeigniter-3,ubuntu-17.10,Php,Apache,Codeigniter 3,Ubuntu 17.10,我跟着的最后一个在这里 我有一个控制器如下所示: <?php defined('BASEPATH') OR exit('No direct script access allowed'); class Login extends CI_Controller { public function index() { $this->load->view('login.html'); } } 将/etc/apache2/apache2.c

我跟着的最后一个在这里

我有一个控制器如下所示:

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

class Login extends CI_Controller {

    public function index()
    {
        $this->load->view('login.html');
    }
}
  • 将/etc/apache2/apache2.conf中的
    AllowOverride None
    的每个实例替换为
    AllowOverride All

  • 启用重写模式:
    sudo a2enmod rewrite
  • 最后重新启动apache2服务
  • 毕竟,我再次访问我的url
    http://localhost/homerent/Login
    我仍然找不到404


    我不知道那有什么问题

    在Ubuntu中,你必须使用虚拟主机才能工作。 对于第一个可用的
    /etc/apache2/sites
    创建
    yourproject.conf
    文件(可能需要根权限,请使用
    sudo
    命令)

    在候机楼

     cd /etc/apache2/sites-available
    
    然后

    sudo nano yourproject.conf

    复制下面的内容并粘贴到其中

    <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>
    
    yourproject
    文件夹中创建.htaccess,其中包含以下内容

    RewriteEngine on
    RewriteCond $1 !^(index\.php|images|robots\.txt)
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php/$1 [L]
    
    然后重新启动apache以使更改生效

    现在,您可以通过url
    http://localhost:3434
    (这将加载defaulf控制器),无需在url中添加项目文件夹

    例如
    http://localhost/homerent/Login
    url是否正在使用now和 设置虚拟主机后
    您可以使用
    http://localhost:3434/Login

    如果未启用mod rewrite,请确保已启用mod rewrite,然后重新启动apache。@Prasanaputtaswamy,我确实使用了此命令
    sudo a2enmod rewrite
    ,但它仍然不起作用。
    $config['base_url'] = 'http://localhost:3434';
    $config['uri_protocol']    = 'REQUEST_URI';
    $config['index_page'] = '';
    
    RewriteEngine on
    RewriteCond $1 !^(index\.php|images|robots\.txt)
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php/$1 [L]