问题
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