【问题标题】:Codeigniter "The requested URL was not found" errorCodeigniter“未找到请求的 URL”错误
【发布时间】:2013-03-22 01:03:57
【问题描述】:

我已经开始使用 codeigniter 构建一个新网站。我一直在尝试在内部链接页面,但由于某种原因我无法做到。这是我的代码中的链接之一

<a href="<?php echo base_url(); ?>site/index">Home</a>

当我点击这个链接时,它会说

The requested URL /basicsite/site/index was not found on this server.

'url' helper 在 autoload.php 中加载

$autoload['helper'] = array('form', 'url', 'html');

我将base_url设置如下

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

$config['index_page'] = 'index.php';

我的任何默认控制器都是

$route['default_controller'] = "site";

“站点”控制器看起来像这样

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

class Site extends CI_Controller
{

function Site()
{
    parent::__construct();
}

public function index()
{
    $this->load->view('templates/site_header');     
    $this->load->view('content');       
    $this->load->view('templates/site_footer');
}

}

不知道我哪里出错了。我需要对 .htaccess 文件做些什么吗?我已经在stackoverflow网站上解决了类似的问题,但找不到解决方案 需要一些帮助。

提前致谢。

【问题讨论】:

  • http://localhost/basicsite/index.php/site/index 适合你吗?
  • @cryptic 是的,但由于某种原因,图像没有像 http://localhost/basicsite/ 那样加载
  • 你是如何加载图像的?请在 HTML 源代码中发布示例生成的图像 URL 作为输出。另请发布您的图片所在的位置。
  • 您需要在 config.php 中的站点 URL 末尾添加一个斜杠。 $config['base_url'] = 'http://localhost/basicsite/';
  • 显然,base_url() 没有读取配置['base_url']。可能是有那种bug,总是做一个空白页来测试php代码到底写了什么。所以&lt;?php echo "base func: ". base_url(); echo "&lt;br&gt;config base url: ". $this-&gt;config-&gt;item('base_url'); ?&gt; 在一个空白的控制器区域可以帮助你看到真正在写什么。此外,文档说要将目的地添加到函数中。 "... 您可以将段作为字符串或数组提供。这是一个字符串示例:echo base_url("blog/post/123");

标签: codeigniter


【解决方案1】:

从你的配置文件中删除 index.php。

【讨论】:

    猜你喜欢
    • 2019-06-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-05
    • 1970-01-01
    相关资源
    最近更新 更多