CodeIgniter 3部署于grease子目录访问控制器报404页面未找到问题求助
CodeIgniter 3 子目录部署404问题排查方案
- 修正.htaccess重写规则
子目录部署必须显式指定RewriteBase参数,修改后的完整.htaccess内容如下:Options +SymlinksIfOwnerMatch Options -Indexes RewriteEngine on # 新增以下行,指定子目录作为重写基准路径 RewriteBase /grease/ RewriteCond $1 !^(index\.php|assets/|robots\.txt|piwik/|crontab/) RewriteRule ^(.*)$ index.php/$1 [L] php_value post_max_size 300M php_value memory_limit 2048M php_value upload_max_filesize 300M - 检查application/config/config.php配置
确认以下两个参数配置正确:// 确认base_url无拼写错误即可 $config['base_url'] = 'https://<url>/grease/'; // 必须将index_page设为空字符串,否则重写规则不生效 $config['index_page'] = ''; - 确认Apache配置生效
- 检查服务器是否启用
mod_rewrite模块 - 检查站点配置中对应目录的
AllowOverride参数是否设为All,否则.htaccess规则不会被加载
- 检查服务器是否启用
- 验证重写规则是否生效
尝试访问带index.php的地址:https://<url>/grease/index.php/Auth,如果可以正常访问,即可确认问题出在重写规则配置上 - 特殊场景:Nginx环境部署
如果使用Nginx作为Web服务器,.htaccess规则不生效,需要在Nginx站点配置中添加以下重写规则:location /grease { try_files $uri $uri/ /grease/index.php?$args; } - 二次确认控制器规范
Linux服务器大小写敏感,可再次检查Auth控制器文件名是否为Auth.php、类名是否为class Auth extends CI_Controller,无拼写、大小写错误。
内容的提问来源于stack exchange,提问作者Grégory Nam
相关产品推荐
相关产品推荐

