CodeIgniter: 404 error on getting JS file

ぐ巨炮叔叔 提交于 2021-02-11 16:58:46

问题


I am installing a project that is based on CodeIgniter. In the login page when I try to login it keeps redirecting me to login page without showing any messages. Looking at http access logs, I can see that the website can not find the js files:

127.0.0.1 - - [07/Apr/2020:14:05:15 -0400] "GET /media/js/jquery-2.1.1.min.js HTTP/1.1" 404 487 "http://localhost/web/" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:74.0) Gecko/20100101 Firefox/74.0"
127.0.0.1 - - [07/Apr/2020:14:05:15 -0400] "GET /media/login_script.js HTTP/1.1" 404 487 "http://localhost/web/" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:74.0) Gecko/20100101 Firefox/74.0"
127.0.0.1 - - [07/Apr/2020:14:05:15 -0400] "GET /media/js/jquery-2.1.1.min.js HTTP/1.1" 404 487 "http://localhost/web/" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:74.0) Gecko/20100101 Firefox/74.0"
127.0.0.1 - - [07/Apr/2020:14:05:15 -0400] "GET /media/login_script.js HTTP/1.1" 404 487 "http://localhost/web/" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:74.0) Gecko/20100101 Firefox/74.0"

I searched about this error and some people suggested to change the .htaccess file. I changed it to the following but still have the same issue.

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]

</IfModule>

Can anyone help me what is the problem? The project is located in /var/www/html/web and I am accessing it using http://localhost/web/


回答1:


Open the application/config/config.php file and set your base URL properly.

$config['base_url'] = 'http://localhost/web';



回答2:


since you can access the file directly, it means your script src path is wrong

check your path, change it with

<script src='<?php echo base_url()?>media/js/jquery-2.1.1.min.js'></script>`
<script src='<?php echo base_url()?>media/login_script.js'></script>`

dont forget to check your base_url setting in your config.php file



来源:https://stackoverflow.com/questions/61086744/codeigniter-404-error-on-getting-js-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!