Search code examples
codeigniterubuntunginxhttp-status-code-404plesk

CodeIgniter 4 Css and Js 404 and 403


I had a running CI4 application and after some unfortunate events, I reinstalled the whole system on my server.

I was using Plesk on Centos 7, and now I and using Ubuntu 22.04. I created a subdomain, then uploaded my CI4 code. I modified my http.conf and append public to the document root.

Next, I checked my app/Config/App.php

public $baseURL = 'https://patron.berkyazilim.com/';

My home page loaded but CSS files were not found.

I checked, I am using

<link rel="stylesheet" href="<?= base_url('css/style.default.css') ?>">

The file is available. But the file returns 404.

here my public/css


custom.css              style.default.css          style.green.min.css      style.pink.min.css.map  style.sea.css          style.violet.min.css
style.blue.css          style.default.min.css      style.green.min.css.map  style.red.css           style.sea.min.css      style.violet.min.css.map
style.blue.min.css      style.default.min.css.map  style.pink.css           style.red.min.css       style.sea.min.css.map
style.blue.min.css.map  style.green.css            style.pink.min.css       style.red.min.css.map   style.violet.css

I can load custom.css but style.default.css won't load.

see:

https://patron.berkyazilim.com/css/custom.css <- lodaing

https://patron.berkyazilim.com/css/style.default.css <- not loading

Here my .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 /

        # Redirect Trailing Slashes...
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_URI} (.+)/$
        #RewriteCond $1 !^(index\.php|assets|assets/css|assets/js|assets/etc|robots\.txt)
        RewriteRule ^ %1 [L,R=301]
        #RewriteRule ^(.*)$ /gestion/index.php/$1 [L]

        # 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 ^([\s\S]*)$ index.php/$1 [L,NC,QSA]

        # 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

Solution

  • Turns out one should not edit the HTTP config (Nginx or Apache) files that Plesk generates. For two reasons:

    1. They won't work.
    2. The files would be regenerated after each restart of the HTTP service.

    Instead, just open your panel, go to Domains-> Hosting & DNS -> Hosting and there update your Document root.

    Doing that solved the problem...