我有一个名为的子域test.mysite.com,并且在名为 project 的文件夹内安装了 CI4。所以 CI4 安装的实际 url 是test.mysite.com/project/public/index.php。我想从 URL 中删除 public/index.php 部分,但继续使用 public 文件夹来保存我的文件,因为它们应该这样做。
我在项目文件夹根目录上使用这个 .htaccess:
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]
<IfModule mod_headers.c>
<FilesMatch "\.(ttf|ttc|otf|eot|woff|woff2|font.css|css|js)$">
Header set Access-Control-Allow-Origin "*"
</FilesMatch>
</IfModule>
Run Code Online (Sandbox Code Playgroud)
但这不起作用。当我访问 test.mysite.com/project 时,它会将我带到服务器文件列表。我知道 .htaccess 文件正在被正确读取,因为当我在那里添加错误时,它会给我一个警告
编辑: CI4 已经在公共文件夹中附带了一个 htaccess:
# Disable directory browsing
Options All -Indexes
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
# If you installed CodeIgniter in a subfolder, you will need …Run Code Online (Sandbox Code Playgroud)