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

在CodeIgniter中添加本地Bootstrap路径时出现404错误求助

Troubleshooting Bootstrap 404 Error in CodeIgniter

Hey there, let's work through this frustrating 404 issue when adding Bootstrap to your CodeIgniter project. I've run into similar snags before, so let's walk through the most common fixes step by step:

  • Double-check your folder name spelling!
    You wrote asserts in your code, but the standard (and correct) folder name is assets—this is a super common typo that trips up a lot of folks. First confirm your project has a folder named assets (not asserts) at the root level, with a css subfolder containing bootstrap.min.css.

  • Verify your base_url configuration
    Head to application/config/config.php and make sure $config['base_url'] is set properly. For example, if your local project lives at http://localhost/my-ci-app/, set it like this:

    $config['base_url'] = 'http://localhost/my-ci-app/';
    

    Leaving this empty can break the base_url() function's path generation entirely.

  • Confirm your file structure matches the path
    Your Bootstrap CSS file should follow this structure:

    your-project-root/
    ├── assets/
    │   └── css/
    │       └── bootstrap.min.css
    ├── application/
    └── system/
    

    If the file is tucked away in a different subfolder (like public/assets/css), adjust the path in your link tag to match.

  • Test the generated URL directly
    Copy the full URL your link generates (e.g., http://localhost/my-ci-app/assets/css/bootstrap.min.css) and paste it into your browser's address bar. If you still get a 404, the file is either missing, in the wrong place, or your server isn't accessing the folder correctly. If it loads fine, try clearing your browser cache or double-checking for typos in your view file.

  • Check your .htaccess rules (if using URL rewriting)
    If you're using an .htaccess file to remove index.php from URLs, make sure it doesn't block access to the assets folder. A working .htaccess should look like this:

    RewriteEngine On
    # Allow access to existing files/folders
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    # Rewrite all other requests to index.php
    RewriteRule ^(.*)$ index.php/$1 [L]
    

    The two RewriteCond lines ensure real files (like your Bootstrap CSS) are served directly instead of being routed through CodeIgniter's index.php.

  • Ensure the URL Helper is loaded
    The base_url() function relies on CodeIgniter's URL Helper. You can load it automatically by adding 'url' to the $autoload['helper'] array in application/config/autoload.php, or load it in your controller with:

    $this->load->helper('url');
    

If none of these fix the issue, feel free to share more details like your CodeIgniter version, exact project folder structure, or any custom .htaccess rules you're using!

内容的提问来源于stack exchange,提问作者Sahan Siriwardana

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.21 03:39:07