【问题标题】:FuelPHP remove public from urlFuelPHP 从 url 中删除 public
【发布时间】:2012-08-02 07:43:20
【问题描述】:

首先抱歉,但我是一个非常大的初学者,所以如果你愿意,可以对这个问题投反对票。

所以我看了很多教程,唯一对我有用的就是把公用文件夹的内容拉出来。

问题是我得到了一堆错误。

错误:

Warning: require(\bootstrap.php) [function.require]: failed to open stream: No such file or directory in C:\EasyPHP\www\fuelphp\index.php on line 33

Fatal error: require() [function.require]: Failed opening required '\bootstrap.php' (include_path='.;C:\php\pear') in C:\EasyPHP\www\fuelphp\index.php on line 33

所以我发现 DOCROOT 是C:\EasyPHP\www\fuelphp\,所以我需要以 localhost/fuelphp/fuel/core 的方式拉取东西

原来的索引是这样的

<?php
/**
 * Set error reporting and display errors settings.  You will want to change these when in production.
 */
error_reporting(-1);
ini_set('display_errors', 1);

/**
 * Website document root
 */
define('DOCROOT', __DIR__.DIRECTORY_SEPARATOR);

/**
 * Path to the application directory.
 */
define('APPPATH', realpath(__DIR__.'/../fuel/app/').DIRECTORY_SEPARATOR);

/**
 * Path to the default packages directory.
 */
define('PKGPATH', realpath(__DIR__.'/../fuel/packages/').DIRECTORY_SEPARATOR);

/**
 * The path to the framework core.
 */
define('COREPATH', realpath(__DIR__.'/../fuel/core/').DIRECTORY_SEPARATOR);

// Get the start time and memory for use later
defined('FUEL_START_TIME') or define('FUEL_START_TIME', microtime(true));
defined('FUEL_START_MEM') or define('FUEL_START_MEM', memory_get_usage());

// Boot the app
require APPPATH.'bootstrap.php';

// Generate the request, execute it and send the output.
try
{
    $response = Request::forge()->execute()->response();
}
catch (HttpNotFoundException $e)
{
    $route = array_key_exists('_404_', Router::$routes) ? Router::$routes['_404_']->translation : Config::get('routes._404_');
    if ($route)
    {
        $response = Request::forge($route)->execute()->response();
    }
    else
    {
        throw $e;
    }
}

// This will add the execution time and memory usage to the output.
// Comment this out if you don't use it.
$bm = Profiler::app_total();
$response->body(
    str_replace(
        array('{exec_time}', '{mem_usage}'),
        array(round($bm[0], 4), round($bm[1] / pow(1024, 2), 3)),
        $response->body()
    )
);

$response->send(true);

比修改成这个

<?php
/**
 * Set error reporting and display errors settings.  You will want to change these when in production.
 */
error_reporting(-1);
ini_set('display_errors', 1);

/**
 * Website document root
 */
define('DOCROOT', '/');

/**
 * Path to the application directory.
 */
define('APPPATH', 'fuel/app/').DIRECTORY_SEPARATOR;

/**
 * Path to the default packages directory.
 */
define('PKGPATH', 'fuel/packages/').DIRECTORY_SEPARATOR;

/**
 * The path to the framework core.
 */
define('COREPATH', 'fuel/core/').DIRECTORY_SEPARATOR;

// Get the start time and memory for use later
defined('FUEL_START_TIME') or define('FUEL_START_TIME', microtime(true));
defined('FUEL_START_MEM') or define('FUEL_START_MEM', memory_get_usage());

// Boot the app
require APPPATH.'bootstrap.php';

// Generate the request, execute it and send the output.
try
{
    $response = Request::forge()->execute()->response();
}
catch (HttpNotFoundException $e)
{
    $route = array_key_exists('_404_', Router::$routes) ? Router::$routes['_404_']->translation : Config::get('routes._404_');
    if ($route)
    {
        $response = Request::forge($route)->execute()->response();
    }
    else
    {
        throw $e;
    }
}

// This will add the execution time and memory usage to the output.
// Comment this out if you don't use it.
$bm = Profiler::app_total();
$response->body(
    str_replace(
        array('{exec_time}', '{mem_usage}'),
        array(round($bm[0], 4), round($bm[1] / pow(1024, 2), 3)),
        $response->body()
    )
);

$response->send(true);

现在公众不在网址中,但是当我打开网站时出现一堆错误,我看到插入的正斜杠和反斜杠,但无法真正找到问题

Warning: require_once(fuel/core/classes\error.php) [function.require-once]: failed to open stream: No such file or directory in C:\EasyPHP\www\fuelphp\fuel\core\base.php on line 25

Fatal error: require_once() [function.require]: Failed opening required 'fuel/core/classes\error.php' (include_path='.;C:\php\pear') in C:\EasyPHP\www\fuelphp\fuel\core\base.php on line 25

请有人给我一个提示,如何修改索引以确保一切正常?

谢谢

【问题讨论】:

    标签: php url fuelphp


    【解决方案1】:

    您不需要修改索引文件来实现您正在尝试的内容。

    Fuel 被设计为驻留在文档根目录 (docroot) 之上。您的 docroot 似乎是 www/。

    这意味着你的目录结构实际上应该如下:

    C:\EasyPHP\fuelphp\
    C:\EasyPHP\www\
    

    FuelPHP zip 文件或 git clone(或者您可以获取它)包含一个名为 public 的文件夹。此文件夹是您的 docroot 的假定名称,因此在您的情况下,public/ 的内容应复制到 www/

    但是,您可以在尝试时将其全部设置在 docroot 中,该过程记录在 FuelPHP 网站 here 上。

    如第 3 点所述,出于安全原因,强烈建议 不要在您的网络服务器的文档根目录中安装 Fuel。

    但是,在某些情况下您希望这样做,[...]

    在这种情况下,您需要一个额外的 .htaccess 文件,您需要将其放入文档中 root,这会将请求重定向到站点根目录到您的公众 文件夹,并且还修改了重写以包括公用文件夹:

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

    index.php的默认配置默认考虑了/fuel/文件夹的位置。以如下路径定义为例

    define('COREPATH', realpath(__DIR__.'/../fuel/core/').DIRECTORY_SEPARATOR);
    
    __DIR__    - Path of current working directory, i.e. wherever index.php is
    ..         - go up a directory, i.e. directory above wherever index.php is
    fuel/      - Fuel folder
    core/      - Core folder within fuel/
    
    realpath() - Resolves the .. to it's real location and makes sure / is correct or changes to \ depending on the OS
    

    你得到不同方向的斜线的原因是你在代码中硬编码了/,而没有使用realpath()

    【讨论】:

    • 将 htaccess 添加到根目录,现在工作正常,最后一个问题是使用这个 htaccess 是否安全?因为现在我可以通过这种方式访问​​它localhost/fueljob 和这种方式localhost/fueljob/public,这不是问题吗?
    • 这不是问题,不是。如果你真的想要,你也可以在通过后一个 URL 访问它时使用 .htaccess 拒绝访问,但这不是问题,是的,我会说它可以安全使用。
    【解决方案2】:

    您还可以使用 VirtualHost 将 http://project.dev/ 定向到您项目的公共路径。

    【讨论】:

      【解决方案3】:

      在你的文件中:

      C:\EasyPHP\www\fuelphp\public\.htaccess

      设置RewriteBase这个值:/easyphp/www/fuelphp/public

      【讨论】:

        猜你喜欢
        • 2016-07-30
        • 2021-09-27
        • 2015-01-14
        • 2020-06-07
        • 1970-01-01
        • 1970-01-01
        • 2015-11-17
        • 2016-03-06
        • 2017-09-28
        相关资源
        最近更新 更多