Bad reference of styles and scripts in cakephp 4.2

I made a site with cakephp 4.2 and when I see the source of that site is referencing bad the css and js scripts because it adds me a folder that shouldn’t be there, this is the image with the site source:

As you can see the folder that shouldn’t appear is marked with a circle.
What should I do to make disappear that folder?

How does your .htaccess look like? How does your Folder Structure look like?
Please check also this Reference: Installation - 4.x

This is how it looks .htaccess:

# Uncomment the following to prevent the httpoxy vulnerability
# See:
#<IfModule mod_headers.c>
#    RequestHeader unset Proxy

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

And this image shows the folder structure:

because I have no clue on .htaccess files, i can only show my files, but can’t explain them.

<IfModule mod_rewrite.c>
    RewriteEngine on
    #the next is for forwarding to https
    RewriteCond %{SERVER_Port} !=443
    RewriteRule ^(.*)$$1 [R=301,L]
    # end of forwarding

    RewriteBase /
    RewriteRule ^(\.well-known/.*)$ $1 [L]
    RewriteRule ^$ webroot/ [L]
    RewriteRule (.*) webroot/$1 [L]

and there should be another htaccess file in your webroot folder:

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

maybe it helps, but as I said, i can’t explain these files:-)


how have you configured which favicon is loaded? Have you configured it at all?

For myself, I have a layout file where I configure my specific favicon using HtmlHelper’s meta() method.

<?= $this->Html->meta('my_favicon.ico', '/my_favicon.ico', ['type' => 'icon']) ?>


I would try this:
The htaccess on you local machine should read

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

However on the web server:

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

The difference is using the “RewriteBase /”

I’m sorry I reopened this topic.
I’m still having problem with the reference, how should I configure .htaccess so that it references correctly the css and script files?
I tried to put the whole path to the app (RewriteBase /web/sistemas/programas_asignaturas/) but it still doesn’t references correctly these files.

It’s almost certainly not a .htaccess issue. What does the code look like that generates those bad links?

This is the code that generates the bad links:

Is the template default.php from layout folder:

 * CakePHP(tm) : Rapid Development Framework (
 * Copyright (c) Cake Software Foundation, Inc. (
 * Licensed under The MIT License
 * For full copyright and license information, please see the LICENSE.txt
 * Redistributions of files must retain the above copyright notice.
 * @copyright     Copyright (c) Cake Software Foundation, Inc. (
 * @link CakePHP(tm) Project
 * @since         0.10.0
 * @license MIT License
 * @var \App\View\AppView $this

$cakeDescription = 'Sistema de Gesti&oacute;n de Trayectos Formativos';
<!DOCTYPE html>
    <?= $this->Html->charset() ?>
    <meta name="viewport" content="width=device-width, initial-scale=1">
        <?= $cakeDescription ?>:
        <?= $this->fetch('title') ?>
    <?= $this->Html->meta('icon') ?>
	<?= $this->Html->meta('csrfToken', $this->request->getAttribute('csrfToken')) ?>

    <link href=",700" rel="stylesheet">

    <?= $this->Html->css(['normalize.min', 'milligram.min', 'cake', 'bootstrap']) ?>
	<?= $this->Html->script('vendor/modernizr-2.6.2-respond-1.1.0.min'); ?>
	<?= $this->Html->script(['vendor/jquery-1.11.0.min']); ?>

    <?= $this->fetch('meta') ?>
    <?= $this->fetch('css') ?>
    <?= $this->fetch('script') ?>
    <nav class="top-nav">
        <div class="top-nav-title">
            <a href="<?= $this->Url->build('/') ?>"><span><?= $cakeDescription ?></span></a>
    <main class="main">
        <div class="container">
            <?= $this->Flash->render() ?>
            <?= $this->fetch('content') ?>
		Desarrollado por <a href="" target="_blank">Mat&iacute;as de Anquin</a> | 2021 &copy; Todos los derechos reservados
	<?= $this->Html->script(['vendor/bootstrap.min','jquery-ui.min','backend','jquery.dataTables','dataTables.bootstrap']); ?>
	<?= $this->Html->css('jquery-ui.min'); ?>
      $(document).ready(function () {
          $('.table-sortable').dataTable( {
              'language': {
                  'url': '//'
          } );

And can you share the output of debug(\Cake\Core\Configure::read('App'));?

ROOT/templates/layout/default.php (line 16)
‘namespace’ => ‘App’,
‘encoding’ => ‘UTF-8’,
‘defaultLocale’ => ‘en_US’,
‘defaultTimezone’ => ‘UTC’,
‘base’ => false,
‘dir’ => ‘src’,
‘webroot’ => ‘webroot’,
‘wwwRoot’ => ‘/var/www/html/web/sistemas/trayectos/webroot/’,
‘fullBaseUrl’ => ‘’,
‘imageBaseUrl’ => ‘img/’,
‘cssBaseUrl’ => ‘css/’,
‘jsBaseUrl’ => ‘js/’,
‘paths’ => [
‘plugins’ => [
(int) 0 => ‘/var/www/html/web/sistemas/trayectos/plugins/’,
‘templates’ => [
(int) 0 => ‘/var/www/html/web/sistemas/trayectos/templates/’,
‘locales’ => [
(int) 0 => ‘/var/www/html/web/sistemas/trayectos/resources/locales/’,

Well, the cssBaseUrl there looks like it should. And following the flow through the HTML helper css file, it looks pretty straight-forward that it should be using this. Do you have some custom HTML helper in place? Or a custom URL helper? Or middleware that adjusts the output before returning it? If you have xdebug, put a breakpoint in HtmlHelper::css, then step through and into other functions to trace what’s going on. If you don’t have xdebug, get it, and do this. :slight_smile: And if for some reason you can’t, then I guess simulate it with a bunch of debug or log statements in that function and the ones it calls (UrlHelper::css, and so on). The great thing about PHP is it’s all interpreted, the code is all there. Nothing at all stopping you from making edits to the core code to debug things, just as long as you put it all back how you found it when you’re done!

I installed xdebug and visual studio code, but for some reason I can’t open it, this is in fedora 31, I didn"t configure anything, can you help me with that please?

There is a special Debug Tab on the left side in VSCode.
If you got the XDebug Extension for VSCode installed you then need to enable listening for XDebug connections.
You will definitely find lots of tutorials when you google that.

Thank you, but it doesn’t open visual studio code, I execute code from the Linux console and it doesn’t do anything, let me clarify that I am connected by scp to the server with putty

Well I expected you are working in a local version of your app. XDebuging a live/remote server is a bit more complicated which i will not step through with you.
You will have to add logging/var_dump or whatever you like to debug it further.

How to get xdebug working in your environment is definitely outside the scope of a CakePHP site. There’s lots of details about how to get it working out there on dedicated sites. Learning how to run and use it is not just helpful for this one thing, it’s great for debugging any issue you may run into.