CodeIgniter 4... documentRoot 未公开... htaccess 不起作用

2024-02-06

我开始涉足 CodeIgniter 4。 完成了一个简单的应用程序。在本地,我将文档根设置为 /public/ ,而在产品托管环境中,我无法将文档根设置为 /public/ 。

相反,它位于 /root 中。

所以结构是这样的:

/root
../admin
../app
../system
../public
../.htaccess
../index.php

我已将 htaccess 从公共文件夹移至根级别。

# Disable directory browsing
Options All -Indexes

# ----------------------------------------------------------------------
# Rewrite engine
# ----------------------------------------------------------------------

# Turning on the rewrite engine is necessary for the following rules and features.
# FollowSymLinks must be enabled for this to work.
<IfModule mod_rewrite.c>
    Options +FollowSymlinks
    RewriteEngine On

    # If you installed CodeIgniter in a subfolder, you will need to
    # change the following line to match the subfolder you need.
    # http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritebase
    RewriteBase /public

    # Redirect Trailing Slashes...
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)/$ /public/$1 [L,R=301]

    # Rewrite "www.example.com -> example.com"
    RewriteCond %{HTTPS} !=on
    RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
    RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]

    # Checks to see if the user is attempting to access a valid file,
    # such as an image or css document, if this isn't true it sends the
    # request to the front controller, index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]

    # Ensure Authorization header is passed along
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>

<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.
    ErrorDocument 404 index.php
</IfModule>

# Disable server signature start
    ServerSignature Off
# Disable server signature end

以及根文件中的index.php:

<?php

// Valid PHP Version?
$minPHPVersion = '7.2';
if (phpversion() < $minPHPVersion)
{
    die("Your PHP version must be {$minPHPVersion} or higher to run CodeIgniter. Current version: " . phpversion());
}
unset($minPHPVersion);

// Path to the front controller (this file)
define('FCPATH', __DIR__ . DIRECTORY_SEPARATOR);

// Location of the Paths config file.
// This is the line that might need to be changed, depending on your folder structure.
$pathsPath = FCPATH . 'app/Config/Paths.php';
// ^^^ Change this if you move your application folder

/*
 *---------------------------------------------------------------
 * BOOTSTRAP THE APPLICATION
 *---------------------------------------------------------------
 * This process sets up the path constants, loads and registers
 * our autoloader, along with Composer's, loads our constants
 * and fires up an environment-specific bootstrapping.
 */

// Ensure the current directory is pointing to the front controller's directory
chdir(__DIR__);

// Load our paths config file
require $pathsPath;
$paths = new Config\Paths();

// Location of the framework bootstrap file.
$app = require rtrim($paths->systemDirectory, '/ ') . '/bootstrap.php';

/*
 *---------------------------------------------------------------
 * LAUNCH THE APPLICATION
 *---------------------------------------------------------------
 * Now that everything is setup, it's time to actually fire
 * up the engines and make this app do its thang.
 */
$app->run();

此外,应用程序配置文件:

<?php namespace Config;

use CodeIgniter\Config\BaseConfig;

class App extends BaseConfig
{

    /*
    |--------------------------------------------------------------------------
    | Base Site URL
    |--------------------------------------------------------------------------
    |
    | URL to your CodeIgniter root. Typically this will be your base URL,
    | WITH a trailing slash:
    |
    |   http://example.com/
    |
    | If this is not set then CodeIgniter will try guess the protocol, domain
    | and path to your installation. However, you should always configure this
    | explicitly and never rely on auto-guessing, especially in production
    | environments.
    |
    */
    public $baseURL = 'http://sub.domain.com';

    /*
    |--------------------------------------------------------------------------
    | Index File
    |--------------------------------------------------------------------------
    |
    | Typically this will be your index.php file, unless you've renamed it to
    | something else. If you are using mod_rewrite to remove the page set this
    | variable so that it is blank.
    |
    */
    public $indexPage = 'index.php';

    /*
    |--------------------------------------------------------------------------
    | URI PROTOCOL
    |--------------------------------------------------------------------------
    |
    | This item determines which getServer global should be used to retrieve the
    | URI string.  The default setting of 'REQUEST_URI' works for most servers.
    | If your links do not seem to work, try one of the other delicious flavors:
    |
    | 'REQUEST_URI'    Uses $_SERVER['REQUEST_URI']
    | 'QUERY_STRING'   Uses $_SERVER['QUERY_STRING']
    | 'PATH_INFO'      Uses $_SERVER['PATH_INFO']
    |
    | WARNING: If you set this to 'PATH_INFO', URIs will always be URL-decoded!
    */
    public $uriProtocol = 'REQUEST_URI';

    /*
    |--------------------------------------------------------------------------
    | Default Locale
    |--------------------------------------------------------------------------
    |
    | The Locale roughly represents the language and location that your visitor
    | is viewing the site from. It affects the language strings and other
    | strings (like currency markers, numbers, etc), that your program
    | should run under for this request.
    |
    */
    public $defaultLocale = 'en';

    /*
    |--------------------------------------------------------------------------
    | Negotiate Locale
    |--------------------------------------------------------------------------
    |
    | If true, the current Request object will automatically determine the
    | language to use based on the value of the Accept-Language header.
    |
    | If false, no automatic detection will be performed.
    |
    */
    public $negotiateLocale = false;

    /*
    |--------------------------------------------------------------------------
    | Supported Locales
    |--------------------------------------------------------------------------
    |
    | If $negotiateLocale is true, this array lists the locales supported
    | by the application in descending order of priority. If no match is
    | found, the first locale will be used.
    |
    */
    public $supportedLocales = ['en'];

    /*
    |--------------------------------------------------------------------------
    | Application Timezone
    |--------------------------------------------------------------------------
    |
    | The default timezone that will be used in your application to display
    | dates with the date helper, and can be retrieved through app_timezone()
    |
    */
    public $appTimezone = 'America/New_York';

    /*
    |--------------------------------------------------------------------------
    | Default Character Set
    |--------------------------------------------------------------------------
    |
    | This determines which character set is used by default in various methods
    | that require a character set to be provided.
    |
    | See http://php.net/htmlspecialchars for a list of supported charsets.
    |
    */
    public $charset = 'UTF-8';

    /*
    |--------------------------------------------------------------------------
    | URI PROTOCOL
    |--------------------------------------------------------------------------
    |
    | If true, this will force every request made to this application to be
    | made via a secure connection (HTTPS). If the incoming request is not
    | secure, the user will be redirected to a secure version of the page
    | and the HTTP Strict Transport Security header will be set.
    */
    public $forceGlobalSecureRequests = false;

    /*
    |--------------------------------------------------------------------------
    | Session Variables
    |--------------------------------------------------------------------------
    |
    | 'sessionDriver'
    |
    |   The storage driver to use: files, database, redis, memcached
    |       - CodeIgniter\Session\Handlers\FileHandler
    |       - CodeIgniter\Session\Handlers\DatabaseHandler
    |       - CodeIgniter\Session\Handlers\MemcachedHandler
    |       - CodeIgniter\Session\Handlers\RedisHandler
    |
    | 'sessionCookieName'
    |
    |   The session cookie name, must contain only [0-9a-z_-] characters
    |
    | 'sessionExpiration'
    |
    |   The number of SECONDS you want the session to last.
    |   Setting to 0 (zero) means expire when the browser is closed.
    |
    | 'sessionSavePath'
    |
    |   The location to save sessions to, driver dependent.
    |
    |   For the 'files' driver, it's a path to a writable directory.
    |   WARNING: Only absolute paths are supported!
    |
    |   For the 'database' driver, it's a table name.
    |   Please read up the manual for the format with other session drivers.
    |
    |   IMPORTANT: You are REQUIRED to set a valid save path!
    |
    | 'sessionMatchIP'
    |
    |   Whether to match the user's IP address when reading the session data.
    |
    |   WARNING: If you're using the database driver, don't forget to update
    |            your session table's PRIMARY KEY when changing this setting.
    |
    | 'sessionTimeToUpdate'
    |
    |   How many seconds between CI regenerating the session ID.
    |
    | 'sessionRegenerateDestroy'
    |
    |   Whether to destroy session data associated with the old session ID
    |   when auto-regenerating the session ID. When set to FALSE, the data
    |   will be later deleted by the garbage collector.
    |
    | Other session cookie settings are shared with the rest of the application,
    | except for 'cookie_prefix' and 'cookie_httponly', which are ignored here.
    |
    */
    public $sessionDriver            = 'CodeIgniter\Session\Handlers\FileHandler';
    public $sessionCookieName        = 'ci_session';
    public $sessionExpiration        = 7200;
    public $sessionSavePath          = WRITEPATH . 'session';
    public $sessionMatchIP           = false;
    public $sessionTimeToUpdate      = 300;
    public $sessionRegenerateDestroy = false;

    /*
    |--------------------------------------------------------------------------
    | Cookie Related Variables
    |--------------------------------------------------------------------------
    |
    | 'cookiePrefix'   = Set a cookie name prefix if you need to avoid collisions
    | 'cookieDomain'   = Set to .your-domain.com for site-wide cookies
    | 'cookiePath'     = Typically will be a forward slash
    | 'cookieSecure'   = Cookie will only be set if a secure HTTPS connection exists.
    | 'cookieHTTPOnly' = Cookie will only be accessible via HTTP(S) (no javascript)
    |
    | Note: These settings (with the exception of 'cookie_prefix' and
    |       'cookie_httponly') will also affect sessions.
    |
    */
    public $cookiePrefix   = '';
    public $cookieDomain   = '';
    public $cookiePath     = '/';
    public $cookieSecure   = false;
    public $cookieHTTPOnly = false;

    /*
    |--------------------------------------------------------------------------
    | Reverse Proxy IPs
    |--------------------------------------------------------------------------
    |
    | If your server is behind a reverse proxy, you must whitelist the proxy
    | IP addresses from which CodeIgniter should trust headers such as
    | HTTP_X_FORWARDED_FOR and HTTP_CLIENT_IP in order to properly identify
    | the visitor's IP address.
    |
    | You can use both an array or a comma-separated list of proxy addresses,
    | as well as specifying whole subnets. Here are a few examples:
    |
    | Comma-separated:  '10.0.1.200,192.168.5.0/24'
    | Array:        array('10.0.1.200', '192.168.5.0/24')
    */
    public $proxyIPs = '';

    /*
    |--------------------------------------------------------------------------
    | Cross Site Request Forgery
    |--------------------------------------------------------------------------
    | Enables a CSRF cookie token to be set. When set to TRUE, token will be
    | checked on a submitted form. If you are accepting user data, it is strongly
    | recommended CSRF protection be enabled.
    |
    | CSRFTokenName   = The token name
    | CSRFCookieName  = The cookie name
    | CSRFExpire      = The number in seconds the token should expire.
    | CSRFRegenerate  = Regenerate token on every submission
    | CSRFRedirect    = Redirect to previous page with error on failure
    */
    public $CSRFTokenName  = 'csrf_test_name';
    public $CSRFCookieName = 'csrf_cookie_name';
    public $CSRFExpire     = 7200;
    public $CSRFRegenerate = true;
    public $CSRFRedirect   = true;

    /*
    |--------------------------------------------------------------------------
    | Content Security Policy
    |--------------------------------------------------------------------------
    | Enables the Response's Content Secure Policy to restrict the sources that
    | can be used for images, scripts, CSS files, audio, video, etc. If enabled,
    | the Response object will populate default values for the policy from the
    | ContentSecurityPolicy.php file. Controllers can always add to those
    | restrictions at run time.
    |
    | For a better understanding of CSP, see these documents:
    |   - http://www.html5rocks.com/en/tutorials/security/content-security-policy/
    |   - http://www.w3.org/TR/CSP/
    */
    public $CSPEnabled = false;

}

当去http://sub.domain.com http://sub.domain.com,我正在获取默认控制器和视图渲染。 然而,链接的 CSS 资源和 JS 资源:https://sub.domain.com/assets/css/style.bundle.css https://sub.domain.com/assets/css/style.bundle.css

都会出现服务器错误。 这些文件的位置实际上是在https://sub.domain.com/public/assets/css/style.bundle.css https://sub.domain.com/public/assets/css/style.bundle.css

但我试图避免在网址中使用 /public/ 。

任何帮助或指导表示赞赏。

RD


理想情况下,您的所有文件夹都应该与 root 处于同一级别。这是假设 /root 是可公开访问的目录。

换句话说,

/admin
/app
/root
   .htaccess
   favicon.ico
   index.php
   robots.txt
   /assets
/system
/vendor
/writable

请注意,没有名为“public”的目录。实际上它以前被称为public,但已更名为“root”。没有要求必须命名public,只是它是您的域名指向的目录。

除了在 app\config 中设置一些内容之外,您应该能够使用所有已分发的文件

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

CodeIgniter 4... documentRoot 未公开... htaccess 不起作用 的相关文章

  • 在多维数组 PHP 的所有键中搜索

    我想在多维数组中的所有键中搜索特定字符串 我只需要弄清楚它是否存在 仅此而已 我想知道访问者的 IP 是否存在于任何数组中 有没有我可以用来执行此操作的 php 函数或方法 我尝试过的每个函数或方法总是返回 false 数组中 数组搜索 数
  • 如何在 json 中输出 javascript 日期

    我正在尝试时间线图表 http code google com apis visualization documentation gallery annotatedtimeline html Data Format http code go
  • 电子商务是否从头开始

    我需要开发一个包含电子商务部分的新网站 我来这里是想从你那里得到一些关于我应该走哪条路的提示 该网站将有一个静态部分 其中包括一些静态页面和用于销售产品的电子商务部分 我是 Django 和 PHP 开发人员 但这是我第一次需要开发电子商务
  • PHP 下载脚本输出损坏的文件

    我正在用 PHP 为我的 CMS 构建一个文件下载类 当时我注意到它以不同的编码格式输出文件 我尝试使用 readfile file get contents fread 但似乎都在做同样的事情 这就像与输出缓冲有关的东西 我使用脚本下载的
  • PHP 的password_verify() 是否可以抵御极长的密码(DoS 攻击)?

    一般攻击场景 2013 年 Django 存在一个普遍漏洞 攻击者可以通过非常大的密码创建极其密集的 CPU 计算 请参阅此处的安全通知 https www djangoproject com weblog 2013 sep 15 secu
  • CakePHP Auth 组件使用 $this->Auth->login() 时未登录;

    我是 cakePHP 的新手 我已经阅读了他们的文档 并且正在遵循他们的简单身份验证示例 我还广泛搜索 包括本网站上的答案 来寻找我的问题的答案 我正在使用 cakePHP 2 0 我的 UsersController 的登录功能如下所示
  • Laravel 5.4 将json保存到数据库

    帮我将 json 保存到数据库 表字段类型 文本 我有带有强制转换数组的模型 class Salesteam extends Model protected casts team members gt array 我想要像这样 index
  • IIS6 中是否有与 .htaccess 等效的基于文件的文件? (不是配置/插件)

    有很多similar对此有疑问 但它们似乎都涉及配置权限或安装插件 我正在寻找一种 愚蠢 的解决方案 即允许从源代码控制部署代码并自动访问某些被阻止的路径 而无需任何人配置服务器 我只需要目录和文件阻止 htaccess 没有其他功能 需要
  • Memcache 不会刷新或清除内存

    我一直在尝试清除我的内存缓存 因为我注意到使用时存储占用了近 30 的服务器内存ps aux 所以我运行了以下 php 代码 memcache new Memcache memcache gt connect localhost 11211
  • Zend RegEx Validator 的自定义有意义的错误消息

    我正在验证表单中的文本字段 如下所示 name new Zend Form Element Text name name gt setLabel First Name gt setRequired true gt addFilter new
  • 从子域中的 ../ 路径

    假设我创建了一个子域 http subdomain mydomain com http subdomain mydomain com 最初是在这个网址 http mydomain com subfolder folder http mydo
  • 当路由不存在时重定向 laravel 4

    我正在使用 laravel 4 当我的项目处于生产模式时 我得到 抱歉 找不到您要查找的页面 当我到达一条不存在的路线时 当我 grep 我的代码时 它在两个地方找到 vendor symfony debug Symfony Compone
  • 彩色 var_dump() 和错误

    我怎样才能将样式设置为var dump 功能和PHP错误样式 如下图所示 目前我有下一个观点var dump with pre var dump pre 没有它将全部在一行中 并且只是纯文本的错误 我搜索了一些 PHP 颜色错误 var d
  • 如何从另一个数组值中过滤数组值并返回新数组? [复制]

    这个问题在这里已经有答案了 我有两个数组 all languages and taken languages 第一个包含所有语言 例如 200 种或其他语言 第二个包含之前选择的语言 从 0 到 200 种 我需要删除所有已采用的语言 ta
  • 控制数据是否存在于数组中

    我在mysql中有两个不同的表 我正在使用curl从json文件中获取数据 我的第一个表名称是 tblclients 该表存储客户端数据 我的第二个表名称是 tblcustomfieldsvalues 该表使用 tblclients 表的
  • 使用 Xpath 进行部分匹配

    我正在尝试创建一个搜索功能 允许使用 Xpath 按歌曲标题或流派进行部分匹配 这是我的 XML 文件
  • PHP Json_encode 将空格更改为加号 +

    我有一个网络应用程序 我首先将 JSON 数据存储在 cookie 中 然后每 x 秒保存到数据库 它只是打开与服务器的连接 服务器读取 cookie 它实际上并不通过 POST 或 GET 发送任何内容 当我保存到 cookie 时 我的
  • PHP 中根据相似值对数组进行分组

    我有一个具有以下结构的数组
  • 我如何向 Windows Server IIS 7 中的文件夹授予权限

    我是 PHP 和 Windows Server 新手 在查看我在 PHP 中创建的表单时遇到以下错误 Error in exception handler The stream or file C inetpub wwwroot wrp a
  • Google Drive 服务帐户上传的位置

    我正在尝试使用服务帐户将文件上传到我的 Google 云端硬盘 当我部署此代码时 我不希望用户给予授权 我希望他们上传到我的帐户 我通过 PHP 使用它 下面是我到目前为止的情况 这段代码是基于官方文档给出的例子 当我运行 php 脚本时

随机推荐