英文:
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
目录内容:
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
我可以加载custom.css
,但无法加载style.default.css
。
查看:
https://patron.berkyazilim.com/css/custom.css <- 正在加载
https://patron.berkyazilim.com/css/style.default.css <- 未加载
这是我的.htaccess
文件内容:
# 禁用目录浏览
Options All -Indexes
# --------------------------------------------------------------------
# 重写引擎
# --------------------------------------------------------------------
# 打开重写引擎对于以下规则和特性是必要的。
# FollowSymLinks必须启用才能使其工作。
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
# 如果您将CodeIgniter安装在子文件夹中,您需要
# 修改以下行以匹配您需要的子文件夹。
# http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritebase
# RewriteBase /
# 重定向尾部斜杠...
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]
# 重写 "www.example.com -> example.com"
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
# 检查用户是否试图访问有效文件,
# 例如图像或css文档,如果不是,它将发送请求到前端控制器,index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\s\S]*)$ index.php/$1 [L,NC,QSA]
# 确保传递Authorization标头
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
<IfModule !mod_rewrite.c>
# 如果我们没有安装mod_rewrite,所有的404都可以
# 被发送到index.php,一切正常工作。
ErrorDocument 404 index.php
</IfModule>
# 禁用服务器签名开始
ServerSignature Off
# 禁用服务器签名结束
英文:
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
答案1
得分: 0
事实证明,不应编辑Plesk生成的HTTP配置(Nginx
或Apache
)文件,有两个原因:
- 它们将无法工作。
- 这些文件将在每次HTTP服务重启后重新生成。
相反,只需打开面板,转到“域名-> 托管与DNS-> 托管”,然后更新您的文档根目录。
这样做解决了问题...
英文:
Turns out one should not edit the HTTP config (Nginx
or Apache
) files that Plesk generates. For two reasons:
- They won't work.
- 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...
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论