Codeigniter: Unable to access the Stylesheets

前端 未结 3 1512
你的背包
你的背包 2021-01-14 19:12

I have the following directory structure of Codeigniter Folder. You can see that I have put all my assets in the assets folder at the root of the application.

3条回答
  •  有刺的猬
    2021-01-14 19:31

    You have multiple options here. The easiest one is to move the assets folder to the same level as the application so that your directory structure is:

    • application
    • system
    • assets
      • css
      • img
      • js

    Because the assets folder is not in a folder with the .htaccess with Deny From All it won't be blocked by your web server.

    Alternatively you can add an .htaccess file in the assets folder with the following rule:

    # /assets/.htaccess
    Allow from all
    

    I haven't tested this but I think it should work.

    Another option is to change the .htaccess and put an exception on the assets folder but it's a very bad idea (with security implications) to remove the Deny From All without writing alternate rules to lock all folders that shouldn't be accessible.

    Also, set your base_url to the folder containing application, system and assets directories (this folder contains Codeigniter's bootstrap/front controller index.php).

    Additionally, I would advise you to echo your urls using the base_url() function:

    base_url("assets/css/bootstrap.min.css");
    

    OR to call a controller/route

    base_url("controller/method");
    

    The base_url function takes into account the value of $config['index_page'] as well as the necessary leading/trailing slashes.

提交回复
热议问题