【问题标题】:Public and Fuel folder in the same subdirectory, but no public/ in the URLPublic 和 Fuel 文件夹在同一个子目录中,但 URL 中没有 public/
【发布时间】:2012-08-14 01:11:37
【问题描述】:

在一遍又一遍地阅读 Fuel PHP 的 Installation Instructions(我很喜欢)之后,我无法弄清楚如何在没有显示公共网址的情况下使应用程序工作 /,并且无需从 docroot 中移动燃料文件夹。 (所以它都是自包含的)。

我的设置是这样的:

/Users/AeroCross/Sites(这是 MAMP 加载所有文件的地方,即 localhost) /Users/AeroCross/Sites/projects/mariocuba(这是 Fuel 应用的根目录)

包含:

    mariocuba/
        .htaccess
        oil
        fuel/
            app/
            core/
            packages/
        public/
            .htaccess

mariocuba 文件夹内的.htaccess

<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>

public 文件夹内的 .htaccess:

<IfModule mod_rewrite.c>
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php/$1 [L]

如果我尝试加载应用程序 (/Users/AeroCross/Sites/projects/mariocuba/),则会出现此错误:

Not found.
The requested URL /public/index.php/ was not found on this server.

我不知道在这里做什么。

我知道这不是为那样工作而设计的,而且我知道这是不安全的,但这是出于开发和版本控制的目的。我可以做些什么(只需对文件系统进行最少的调整)来完成这项工作?

值得注意的是,我的config.php 文件配置了base_url = nullindex_file = null

任何帮助表示赞赏!

【问题讨论】:

  • 你能访问http://your.domain.com/public/index.php吗?
  • @JonLin 如果我这样做,我会得到燃料生成的 404 (like this)
  • 那么这个index.php 文件应该在哪里?
  • @JonLin 就在那里。就是这样:我不知道为什么我会收到 404,因为文件实际上就在那里。我猜这是某种路由/重写失败。

标签: php apache .htaccess fuelphp fuelphp-routing


【解决方案1】:

从 /mariocuba 中删除现有的 .htaccess 文件,将 /mariocuba/public 的内容(包括 .htaccess)移动到 /mariocuba,然后编辑 index.php。

变化:

/**
 * 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);

收件人:

/**
 * 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);

这在此处的安装说明中有详细说明:http://docs.fuelphp.com/installation/instructions.html#/manual

【讨论】:

  • 你真是上天堂了,好先生。我从远处向你致敬。完美运行!
  • 这确实有效,但出于某种原因,它的级别更深,那里更安全。因此,以这样一种方式限制它,使发送到更深层次的所有内容都会模仿这一点,并在需要时降低更新框架的难度。
【解决方案2】:

在你的根目录中添加一个 .htaccess 文件并使用以下重写规则:

<IfModule mod_rewrite.c>
    RewriteEngine on

    RewriteBase /YOUR_LOCAL_PROJECT_FOLDER/public

    RewriteRule ^(/)?$ index.php/$1 [L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d

    RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

注意: 将 .htaccess 上传到主机后,您需要对其进行编辑(因为它无法动态计算。

【讨论】:

  • 这运行得非常好(几乎完美),但没有正确生成 URL(由 Assets 和 Html 类)。他们都有 public/ 前缀——对此有什么想法吗?
  • 您是否在主配置中设置了 base_url?
【解决方案3】:

如果你想隐藏公共文件夹下的所有内容(我经常这样做),请使用它作为根目录中的一个:

RewriteEngine on
RewriteRule ^(.*) public/$1 [L]

这可以确保所有资源也被重定向到公共。所以所有不公开的东西都是绝对安全的。

【讨论】:

  • 如果我将它添加到我的根目录 (mariocuba/),进入 localhost/projects/mariocuba(根目录)会发出 404。localhost/projects/mariocuba/public 可以工作。它可以按您的预期工作,但我需要的是无需在 URL 中引用它即可访问公用文件夹,并将燃料文件夹与公用文件夹处于同一级别。
猜你喜欢
  • 1970-01-01
  • 2019-08-14
  • 1970-01-01
  • 2018-12-22
  • 2014-02-06
  • 2015-04-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多