CSS and JS not found when moving Kirby from local to remote server

Hi there,
I developed a Kirby website in a local folder (with the Kirby PHP built-in server) and then linked a CSS file in a header.php snippet and a JS file in a footer.php snippet. For this I used the css() and js() functions with relative paths.

Everything was working fine on the local environment but when I moved the files on a remote server through FTP the CSS and JS files I added in the header.php and footer.php snippets were not loaded anymore. When I access them through an absolute path they display a 404 page but actually the path is correct. I tried different ways to link the CSS and JS files to the website (also by hard coding an absolute path) and tested the Kirby website on different remote servers (and domains) too but without luck.

I still have to buy the Kirby license. I don’t know is that is the problem but in case it would have been better to communicate this and not just making this not working. I hope that’s not the case.

Do you have any suggestions?

EDIT: I figured out that there must be a problem with the assets folder. The CSS file (e.g.) is stored like this “kirby/assets/css/style.css” and it is not working. If I move the file in the website root like this it is correctly linked.

I don’t know if storing files in the Kirby website root is a safe thing to do and it would be better to use the “assets” folder for this.

You have to add the files like this, example for stylesheet:

<?= css('assets/css/style.css'); ?>

Yes, I used that but unfortunately it is not working (the generated link is correct but goes to a 4040 page).

This is the path to the CSS file for example (the website is in a subdirectory) which goes to a 404 page:
https://www.mydomain.com/subdirectory/kirby/assets/css/style.css

I tried to create another folder (“files”) in the website root (https://www.mydomain.com/subdirectory/files/css/style.css) and it is working now.
I wonder why there is such a problem with the Kirby assets folder.

Why is the assets folder inside the kirby folder? Folder structure should look like this:

Hi @moonwalk, sorry for this late reply.
That was the problem! I don’t know why it was in the wrong position (maybe I just messed up with files). Thanks!

Access to the /kirby folder is blocked via .htaccess(Apache web server), and you shouldn’t make any changes inside that folder in general.

1 Like