【问题标题】:Kohana 404 error: Requested URL not foundKohana 404 错误:未找到请求的 URL
【发布时间】:2014-01-05 15:11:40
【问题描述】:

。 大家好,

我正在开发一个学校项目的网站。 最近我在 Biberbit.com 上购买了自己的网站空间并想上传我的网站。 当我上传它时,我在屏幕上看到以下错误:

Kohana_HTTP_Exception [ 404 ]: The requested URL / was not found on this server.

我的项目使用的是 Kohana 框架版本 3.3.1 我已经有了 .htaccess 文件,并且文件名/目录名都是小写的。 我使用的是默认路由:

Route::set('default', '(<controller>(/<action>(/<id>)))')
->defaults(array(
    'controller' => 'welcome',
    'action'     => 'index',
));

最初我认为它可能是 bootstrap.php 文件中的 default_url,所以我将这些行更改为:

Kohana::init(array(
    'base_url'   => '/',
    'index_file' => FALSE,
));

我在多个网站上寻找解决方案,但找不到适合我的解决方案。 谁能想到我可能会想念的东西? 我的链接也使用URL::site(),所以我不认为这是导致它的原因。

您可以在http://www.biberbit.com查看错误和/或网站

编辑: .htaccess 根据要求

# Turn on URL rewriting
RewriteEngine On

# Installation directory
RewriteBase /

# Protect hidden files from being viewed
<Files .*>
    Order Deny,Allow
    Deny From All
</Files>

# Protect application and system files from being viewed
RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L]

# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT]

【问题讨论】:

  • 你能添加 .htaccess 吗?
  • @kingkero 我想我发现了安装目录的 .htaccess 中有什么问题。
  • 更改RewriteBase后是否有效?
  • @kingkero 不,它设置为“/”,但它似乎无法修复 404。仍然可以正确设置它。
  • 一件事让我感到困惑:当我使用 FTP 客户端连接到服务器时,它会将我发送到 /,然后我转到 domain/biberbit.com/public_html,这是我的代码所在的位置.这无关紧要吗?

标签: php url http-status-code-404 kohana


【解决方案1】:

base_url 设置错误,它应该是空的(因为您在 Web 根目录上)。同样取决于您是否拥有 Linux,文件名不得全部小写,但您可以在代码中使用它们。所以默认控制器是Welcome.php 而不是welcome.php

【讨论】:

  • 奇怪的是,我最初尝试了空的 base_url,所以它必须是文件名。我会检查一下,然后把结果告诉你。文件 url 中的名称总是小写,但在类名中它是 Controller_Welcome for welcome.php。
  • 我已更改文件名以反映类名并清空 base_url 字符串,但它仍然给我 404。
  • 很抱歉,如果文件名正确并正确设置base_url,它应该可以工作..
【解决方案2】:

Kohana_HTTP_Exception [ 404 ]: The requested URL / was not found on this server. 异常通常在 Kohana 找不到对应的操作方法来处理请求时抛出。

确保你有 Controller_Welcome 类和 action_index 方法。

您还可以检查异常回溯并找出导致异常的确切原因。您很可能会在 if(!method_exists(...)) 块中的 SYSPATH/classes/Kohana/Controller.php 文件中看到 Exeption。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-01-05
    • 2015-07-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多