Cakephp not loading css and js files

2019-08-03 00:29发布

I seriously can't understand what is going on here. I just uploaded my web app from localhost to new domain-name on Windows IIS Server. When I try to access the web app, CSS files and images are not loaded and I get the following error:

"CssController could not be found."

I don't understand why it is doing this. Although I've written code like this in my default.ctp:

 echo $this->html->css('generic');

CSS files are placed in:

 app\webroot\css

I have searched on Google and have tried everything, I even uncommented the line:

Configure::write('App.baseUrl',env('SCRIPT_NAME')); in core.php

But I still cannot get this to work. Please help me to resolve this issue.

1条回答
Summer. ? 凉城
2楼-- · 2019-08-03 00:40

Double check that you have all the .htaccess files in place. Also making sure /app/webroot/ has its .htaccess file:

<IfModule mod_rewrite.c>
   RewriteEngine On
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>

Your request is trying to get the css file from /css/ but i'm thinking you don't have the proper .htaccess files in place to route it to the webroot and not to a controller!

also check if mod_rewrite is enabled

Edit: and then I saw the IIS part, you need some IIS equivalent to mod_rewrite

In this article you find all the information required for successfully run CakePHP web applications under Microsoft IIS web server: http://bakery.cakephp.org/articles/filippo.toso/2008/01/29/cakephp-on-iis

Here is a related question about getting cake to work on IIS: CakePHP 2.2.2 not working on Windows IIS7

查看更多
登录 后发表回答