【问题标题】:Codeigniter 3 : 404 page error, .htaccess not workingCodeigniter 3:404 页面错误,.htaccess 不工作
【发布时间】:2015-08-07 18:59:53
【问题描述】:

它可能是关于 Codeigniter + 404 页面错误的旧的和常规的查询。我已经尝试从以前的 stackoverflow 问题中回答这个问题。但是,我无法解决我的问题。
我已将 Codeigniter 项目从另一个系统(Ubuntu OS 64 位)复制到 Ubuntus OS 系统。但是,我默认得到 404 页。如果我给 http://localhost/project/index.php/admin/login 它的工作但不是 http://localhost/project/admin/login 或 http://localhost/project。
这是我的配置: config.php

    $config['base_url'] = 'http://localhost/html/project';

    $config['modules_locations'] = array(
        APPPATH.'modules/' => '../modules/',
    );
    $config['index_page'] = '';
    $config['uri_protocol'] = 'AUTO'; 

还有我的 .htaccess 文件:

Options FollowSymLinks
<IfModule mod_rewrite.c>
    RewriteEngine on

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule> 
<IfModule !mod_rewrite.c>
    ErrorDocument 404 /index.php
</IfModule> 

【问题讨论】:

  • 我也试过a2enmod rewrite
  • 你重启服务器了吗?
  • 使用 vhost 配置,使用 hosts 文件设置本地域并尝试一次。然后将基本 url 保留为空白。

标签: php apache .htaccess codeigniter codeigniter-3


【解决方案1】:

检查 mod rewrite 是否开启。 如果您使用的是 apache2:

sudo a2enmod rewrite

然后重启apache。

sudo service apache2 restart

【讨论】:

  • 我在问题中提到过
  • mod 重写有问题。你能发布你的虚拟主机配置文件吗?
  • 哦,您的基本网址。您没有使用虚拟主机。尝试创建一个它比这个更简单。
  • 下载了新的 codeigniter,创建了 .htaccess 文件。它的工作,没有 index.php。
【解决方案2】:

尝试像这样重写它:

<IfModule mod_rewrite.c>

    RewriteEngine On
    RewriteBase /

    #Removes access to the system folder by users.
    #Additionally this will allow you to create a System.php controller,
    #previously this would not have been possible.
    #'system' can be replaced if you have renamed your system folder.
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    #When your application folder isn't in the system folder
    #This snippet prevents user access to the application folder
    #Rename 'application' to your applications folder name.
    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    #Checks to see if the user is attempting to access a valid file,
    #such as an image or css document, if this isn't true it sends the
    #request to index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.

    ErrorDocument 404 /index.php
</IfModule>

【讨论】:

  • 只是为了确保您的所有控制器和模型文件名的第一个字母大写?
  • 我将控制器和模型文件名的首字母改为大写。没有任何改变
  • mod_rewrite 是否在 apache 中开启?请确保您也重新启动。
  • mod_rewrite 是一个 Apache 模块,与 php.ini 无关,是的,它已启用。
  • 这是什么:$config['modules_locations'] 做什么?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-09-19
  • 2018-07-22
  • 2016-12-06
  • 2012-06-22
  • 2018-06-18
  • 2019-03-13
相关资源
最近更新 更多