php - 在共享托管公共资产中部署 codeigniter 4 结果为 404
问题描述
我有一个全新的 codeigniter 4 项目设置,在本地运行良好,我能够加载资产。当我在线上传它时,资产无法加载,导致 404,但我能够加载视图。
这是我的 htaccess,默认包含以下 codeigntier 文件public
:
# 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
RewriteRule ^(.*)/$ /$1 [L,R=301]
# 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
这是我对root
路径所做的更新,它使视图工作,但最初我只是看到目录索引而不是视图:
DirectoryIndex /public/index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|assets|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./public/index.php/$1 [L,QSA]
所以我现在有两个 htaccess,一个在root
其中,一个在其中public_html
,public
但仍然无法加载资产。
解决方案
推荐阅读
- reactjs - 级联查询 GraphQL
- html - 悬停效果处于活动状态时如何显示垂直文本
- android - Android 11:DocumentFile findFile() 太慢
- c++ - 模板或成员函数选择
- python - pypi包导入python文件而不是包
- c++ - 升级到 macOS Big Sur 11.01 后,Cocos2d-x 4.0 app build 不再工作(错误:没有这样的文件或目录:'/usr/lib/libz.dylib')
- prolog - 语法错误:预期运算符(SWI Prolog)
- r - 如何根据相同的值计算 R Dataframe 中的百分比?
- reactjs - 在 React 中登录/注册后重定向到邀请链接
- javascript - 我没有使用 FETCH API 从 Java Servlet 获取响应数据