【问题标题】:CakePHP Images in webroot not displaying in Productionwebroot中的CakePHP图像未在生产中显示
【发布时间】:2021-12-07 23:08:50
【问题描述】:

我昨天已将我的网站推送到生产环境,我创建的 3 个 .htaccess 文件一切正常。唯一的问题是我的 webroot 文件夹中的图像没有显示。 我用 $this->Url->image('pages/' . $page->image)

给他们打电话

在 html 中呈现的链接:

背景图片:url(/app/img/pages/home.jpg);

'App' => [
    'namespace' => 'App',
    'encoding' => env('APP_ENCODING', 'UTF-8'),
    'defaultLocale' => env('APP_DEFAULT_LOCALE', 'fr_FR'),
    'defaultTimezone' => env('APP_DEFAULT_TIMEZONE', 'Europe/Brussels'),
    'base' => false,
    'dir' => 'src',
    'webroot' => 'webroot',
    'wwwRoot' => WWW_ROOT,
    //'baseUrl' => env('SCRIPT_NAME'),
    'fullBaseUrl' => false,
    'imageBaseUrl' => 'img/',
    'cssBaseUrl' => 'css/',
    'jsBaseUrl' => 'js/',
    'paths' => [
        'plugins' => [ROOT . DS . 'plugins' . DS],
        'templates' => [ROOT . DS . 'templates' . DS],
        'locales' => [RESOURCES . 'locales' . DS],
    ],
],

/var/htdocs/.htaccess

<IfModule mod_rewrite.c>
   RewriteEngine On
   RewriteBase /
   RewriteRule    ^$ app/webroot/    [L]
   RewriteRule    (.*) app/webroot/$1 [L]
</IfModule>

/app/.htaccess

<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteRule    ^$    webroot/    [L]
  RewriteRule    (.*) webroot/$1    [L]
</IfModule>

/app/webroot/.htaccess

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^ index.php [L]
</IfModule>

谢谢。

【问题讨论】:

  • 如果添加 'fullbase' => true 会怎样?例如$this->Url->image('pages/' . $page->image, ['fullBase' => true])
  • 我已经试过了,没有任何改变。
  • 也许尝试将 RewriteBase / 移动到 /app/.htaccess 而不是 /app/webroot/.htaccess?
  • 也不工作...:/
  • 你能直接访问那个文件吗?试试background-image:url("/img/pages/home.jpg");

标签: .htaccess cakephp cakephp-4.x


【解决方案1】:

这是我的错误日志

2021-10-21 13:18:34 错误:[Cake\Http\Exception\MissingControllerException] 找不到控制器类 Img。在第 226 行的 /homepages/20/d887310999/htdocs/app/vendor/cakephp/cakephp/src/Controller/ControllerFactory.php 堆栈跟踪:

  • /homepages/20/d887310999/htdocs/app/vendor/cakephp/cakephp/src/Controller/ControllerFactory.php:65
  • /homepages/20/d887310999/htdocs/app/vendor/cakephp/cakephp/src/Http/BaseApplication.php:311

请求网址:/img/pages/home.jpg

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-05-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-11
    • 1970-01-01
    • 2011-11-07
    相关资源
    最近更新 更多