【问题标题】:codeigniter page not found 404找不到codeigniter页面404
【发布时间】:2020-07-14 05:25:09
【问题描述】:

我正在开发由其他人使用 codeIgniter 制作的网站,当我将其上传到本地服务器时,它说找不到对象,所以我添加了 .htacess 文件以从链接中删除 index.php

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

我遇到了另一个问题,即找不到页面显示 404 页面(之前不是同一个问题) 我的配置文件是这样的, 基本网址:

$root  = "https://".$_SERVER['HTTP_HOST'];
$root .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);
$config['base_url'] = $root;

索引页面: $config['index_page'] = '';

uri 协议: $config['uri_protocol'] = 'REQUEST_URI';

当我在链接中添加“index.php”时它就可以工作了。

【问题讨论】:

  • 所以我决定在新项目(只有欢迎页面)上尝试它,它通过添加 .htacess 文件来工作,这让我感到困惑
  • 将此信息添加到新答案而不是评论中,并通过勾选将其设置为“已接受的答案”。
  • 问题仍未解决,因为它在我启动新项目文件夹时对我有用,但在我正在处理的文件夹中仍然存在同样的问题

标签: php .htaccess codeigniter xampp


【解决方案1】:

在 .htaccess 和配置中试试这个

RewriteEngine On

RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]


$config['base_url'] = '';
$config['index_page'] = '';

or

$config['base_url'] = 'put-here-your-local-ip';
$config['index_page'] = '';

【讨论】:

    【解决方案2】:

    如果您使用 Xampp,请检查您的项目文件夹 在您的 htaccess 文件中,您必须将 RewriteBase 设置为您的文件夹名称

    RewriteBase /YOUR_PROJECT/
    

    检查您在 application/config/config.php 中的配置文件

    $config['base_url']  =  "http://".$_SERVER['HTTP_HOST'];
    $config['base_url'] .= preg_replace('@/+$@', '', dirname($_SERVER['SCRIPT_NAME'])).'/';
    

    检查 application/config/route.php 中的路由文件

    $route['default_controller'] = 'YOUR_Control_NAME';
    

    【讨论】:

      猜你喜欢
      • 2019-12-02
      • 1970-01-01
      • 2016-11-14
      • 1970-01-01
      • 1970-01-01
      • 2013-02-28
      • 2016-12-06
      • 1970-01-01
      相关资源
      最近更新 更多