CodeIgniter 4 CSS 和 JS 404 和 403

huangapple go评论98阅读模式
英文:

CodeIgniter 4 Css and Js 404 and 403

问题

我有一个正在运行的CI4应用程序,经过一些不幸的事件后,我重新安装了整个服务器系统。

我之前在Centos 7上使用Plesk,现在我在使用Ubuntu 22.04。我创建了一个子域,然后上传了我的CI4代码。
我修改了我的http.conf文件,并将public添加到文档根目录。

接下来,我检查了我的app/Config/App.php文件

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

我的首页加载了,但CSS文件找不到。

我检查了,我正在使用

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

文件是可用的。但是文件返回404。

这是我的public/css目录内容:

  1. custom.css style.default.css style.green.min.css style.pink.min.css.map style.sea.css style.violet.min.css
  2. style.blue.css style.default.min.css style.green.min.css.map style.red.css style.sea.min.css style.violet.min.css.map
  3. style.blue.min.css style.default.min.css.map style.pink.css style.red.min.css style.sea.min.css.map
  4. style.blue.min.css.map style.green.css style.pink.min.css style.red.min.css.map style.violet.css

我可以加载custom.css,但无法加载style.default.css

查看:

https://patron.berkyazilim.com/css/custom.css <- 正在加载

https://patron.berkyazilim.com/css/style.default.css <- 未加载

这是我的.htaccess文件内容:

  1. # 禁用目录浏览
  2. Options All -Indexes
  3. # --------------------------------------------------------------------
  4. # 重写引擎
  5. # --------------------------------------------------------------------
  6. # 打开重写引擎对于以下规则和特性是必要的。
  7. # FollowSymLinks必须启用才能使其工作。
  8. <IfModule mod_rewrite.c>
  9. Options +FollowSymlinks
  10. RewriteEngine On
  11. # 如果您将CodeIgniter安装在子文件夹中,您需要
  12. # 修改以下行以匹配您需要的子文件夹。
  13. # http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritebase
  14. # RewriteBase /
  15. # 重定向尾部斜杠...
  16. RewriteCond %{REQUEST_FILENAME} !-d
  17. RewriteCond %{REQUEST_URI} (.+)/$
  18. #RewriteCond $1 !^(index\.php|assets|assets/css|assets/js|assets/etc|robots\.txt)
  19. RewriteRule ^ %1 [L,R=301]
  20. #RewriteRule ^(.*)$ /gestion/index.php/$1 [L]
  21. # 重写 "www.example.com -> example.com"
  22. RewriteCond %{HTTPS} !=on
  23. RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
  24. RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
  25. # 检查用户是否试图访问有效文件,
  26. # 例如图像或css文档,如果不是,它将发送请求到前端控制器,index.php
  27. RewriteCond %{REQUEST_FILENAME} !-f
  28. RewriteCond %{REQUEST_FILENAME} !-d
  29. RewriteRule ^([\s\S]*)$ index.php/$1 [L,NC,QSA]
  30. # 确保传递Authorization标头
  31. RewriteCond %{HTTP:Authorization} .
  32. RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
  33. </IfModule>
  34. <IfModule !mod_rewrite.c>
  35. # 如果我们没有安装mod_rewrite,所有的404都可以
  36. # 被发送到index.php,一切正常工作。
  37. ErrorDocument 404 index.php
  38. </IfModule>
  39. # 禁用服务器签名开始
  40. ServerSignature Off
  41. # 禁用服务器签名结束
英文:

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 = &#39;https://patron.berkyazilim.com/&#39;;

My home page loaded but CSS files were not found.

I checked, I am using

&lt;link rel=&quot;stylesheet&quot; href=&quot;&lt;?= base_url(&#39;css/style.default.css&#39;) ?&gt;&quot;&gt;

The file is available. But the file returns 404.

here my public/css

  1. custom.css style.default.css style.green.min.css style.pink.min.css.map style.sea.css style.violet.min.css
  2. style.blue.css style.default.min.css style.green.min.css.map style.red.css style.sea.min.css style.violet.min.css.map
  3. style.blue.min.css style.default.min.css.map style.pink.css style.red.min.css style.sea.min.css.map
  4. 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

  1. # Disable directory browsing
  2. Options All -Indexes
  3. # ----------------------------------------------------------------------
  4. # Rewrite engine
  5. # ----------------------------------------------------------------------
  6. # Turning on the rewrite engine is necessary for the following rules and features.
  7. # FollowSymLinks must be enabled for this to work.
  8. &lt;IfModule mod_rewrite.c&gt;
  9. Options +FollowSymlinks
  10. RewriteEngine On
  11. # If you installed CodeIgniter in a subfolder, you will need to
  12. # change the following line to match the subfolder you need.
  13. # http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritebase
  14. # RewriteBase /
  15. # Redirect Trailing Slashes...
  16. RewriteCond %{REQUEST_FILENAME} !-d
  17. RewriteCond %{REQUEST_URI} (.+)/$
  18. #RewriteCond $1 !^(index\.php|assets|assets/css|assets/js|assets/etc|robots\.txt)
  19. RewriteRule ^ %1 [L,R=301]
  20. #RewriteRule ^(.*)$ /gestion/index.php/$1 [L]
  21. # Rewrite &quot;www.example.com -&gt; example.com&quot;
  22. RewriteCond %{HTTPS} !=on
  23. RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
  24. RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
  25. # Checks to see if the user is attempting to access a valid file,
  26. # such as an image or css document, if this isn&#39;t true it sends the
  27. # request to the front controller, index.php
  28. RewriteCond %{REQUEST_FILENAME} !-f
  29. RewriteCond %{REQUEST_FILENAME} !-d
  30. RewriteRule ^([\s\S]*)$ index.php/$1 [L,NC,QSA]
  31. # Ensure Authorization header is passed along
  32. RewriteCond %{HTTP:Authorization} .
  33. RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
  34. &lt;/IfModule&gt;
  35. &lt;IfModule !mod_rewrite.c&gt;
  36. # If we don&#39;t have mod_rewrite installed, all 404&#39;s
  37. # can be sent to index.php, and everything works as normal.
  38. ErrorDocument 404 index.php
  39. &lt;/IfModule&gt;
  40. # Disable server signature start
  41. ServerSignature Off
  42. # Disable server signature end

答案1

得分: 0

事实证明,不应编辑Plesk生成的HTTP配置(NginxApache)文件,有两个原因:

  1. 它们将无法工作。
  2. 这些文件将在每次HTTP服务重启后重新生成。

相反,只需打开面板,转到“域名-> 托管与DNS-> 托管”,然后更新您的文档根目录。

这样做解决了问题...

英文:

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-&gt; Hosting &amp; DNS -&gt; Hosting and there update your Document root.

Doing that solved the problem...

huangapple
  • 本文由 发表于 2023年6月8日 03:15:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/76426452.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定