You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

CodeIgniter 3.1.8仅能访问默认控制器,其他控制器报404求助

Fixing CodeIgniter 3.1.8 404 Errors on FTP Server (Only Default Controller Works)

Hey there, let's work through this 404 issue you're hitting with your CodeIgniter project on the FTP server. I've reviewed your configs and .htaccess attempts, so here are the most likely fixes to get your other controllers working:

1. Fix Your .htaccess Paths (Critical!)

The biggest issue I see is that your previous .htaccess files used example paths (/materials-library/, /sandbox/ci/) instead of matching your actual project directory (/my_project/). Here's the corrected version tailored to your setup:

<IfModule mod_rewrite.c>
    RewriteEngine On
    # Match your project's subdirectory exactly
    RewriteBase /my_project/
    # Ignore requests for existing files/directories
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    # Route all other requests to CodeIgniter's index.php
    RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
    # Fallback if mod_rewrite isn't enabled
    ErrorDocument 404 /my_project/index.php
</IfModule>

Upload this to the root of your my_project folder (same directory as CodeIgniter's index.php).

2. Verify mod_rewrite is Enabled on the Server

Lots of shared hosting providers disable mod_rewrite by default. To check:

  • Create a file named phpinfo.php with this content:
    <?php phpinfo(); ?>
    
  • Upload it to your my_project folder and access it via your browser (e.g., https://*****.net/my_project/phpinfo.php).
  • Search for mod_rewrite in the output. If it's missing, reach out to your hosting provider to enable it.

3. Check Controller Naming (Case Sensitivity Matters!)

CodeIgniter 3 has strict naming rules, and Linux servers (most FTP hosts) are case-sensitive—something Windows (your local env) ignores. Make sure:

  • Controller filenames use Uppercase CamelCase (e.g., About.php, not about.php or about_controller.php).
  • The class inside the file matches the filename exactly:
    class About extends CI_Controller {
        // ... your code
    }
    

If your controller is named Main.php (matching your default controller), double-check other controllers follow this rule.

4. Confirm File Permissions

Your server might not have permission to read your controller files. Use your FTP client or hosting control panel to set:

  • Directory permissions to 755
  • File permissions to 644
    Avoid setting permissions to 777 (it's insecure!).

5. Double-Check Your base_url and Server Directory Structure

Ensure your project is actually located in the /my_project/ subdirectory on the server (e.g., public_html/my_project/). If it's in a different folder, update $config['base_url'] in application/config/config.php to match.

Start with the .htaccess fix first—it's the most common culprit here. If that doesn't work, move through the other checks one by one.

内容的提问来源于stack exchange,提问作者Bernando Purba

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 07:19:49