Javascript 404 not found, but PHP and CSS loading
Solution 1
It looks like there was an alias in your ./conf.d/javascript-common.conf:
file that was causing Apache to look in the wrong place. As you noted, deleting those entries fixed the problem and Apache was happy.
Solution 2
This worked for me
sudo a2disconf javascript-common
This removes the javascript-common.conf
from conf-available
and conf-enabled
.
Related videos on Youtube
Pete
Updated on September 18, 2022Comments
-
Pete almost 2 years
I've got a Ubuntu 10.04.4 LTS cloud server running the default LAMP stack.
My website is serving my PHP pages, the images and CSS to go with them, and most of my JS is loading, but there is a particular folder that is not loading the javascript files.
If I visit my site, site.com/javascript/search.js then I get a 404. If I visit site.com/includes/formvalidation.js then the JS file loads.
This shows the permissions on the includes and javascript folder:
user@server~site/httpdocs$ ls -la | grep includes drwxr-xr-x 5 user www-data 4096 Jun 14 23:53 includes user@server~site/httpdocs$ ls -la includes | grep .js -rwxr-xr-x 1 user www-data 20974 Mar 2 22:33 formvalidation.js user@server~site/httpdocs$ ls -la | grep javascript drwxr-xr-x 3 user www-data 4096 Jun 3 11:03 javascript user@server~site/httpdocs$ ls -la javascript | grep .js -rwxrw-r-x 1 user www-data 7276 Mar 2 22:33 calendar.js -rwxrw-r-x 1 user www-data 33321 Jun 3 11:03 cookieControl-5.1.min.js -rwxrw-r-x 1 user www-data 15552 Mar 2 22:33 image_display.js -rwxrw-r-x 1 user www-data 21130 Mar 2 22:33 popcalendar.js -rwxrw-r-x 1 user www-data 67956 Mar 2 22:33 search.js -rwxrw-r-x 1 user www-data 555 Mar 31 00:15 sell.js -rwxrw-r-x 1 user www-data 318 Mar 31 00:15 sign_in.js -rwxrw-r-x 1 user www-data 142 Mar 31 00:15 update.js
So the file is uploaded, it has the same permissions as other files in includes, and the includes and javascript folder both have the same permission.
There's no .htaccess file, and this works fine locally on my Dev server, it's only when I push live I get a problem.
UPDATE: I made a file, test.js and put it at the root. This could be viewed at site.com/test.js. I moved that, `mv test.js javascript/* and visiting site.com/javascript/test.js gives a 404
UPDATE: Checking /var/log/apache2/error.log shows File does not exist: /usr/share/javascript/search.js
UPDATE: I've searched for javscript in my /etc/apache2 folder and found this:
user@site:/etc/apache2$ grep -iR javascript ./ ./mods-available/deflate.conf: AddOutputFilterByType DEFLATE application/x-javascript application/javascript application/ecmascript ./mods-enabled/deflate.conf: AddOutputFilterByType DEFLATE application/x-javascript application/javascript application/ecmascript ./conf.d/javascript-common.conf:Alias /javascript /usr/share/javascript/ ./conf.d/javascript-common.conf:<Directory "/usr/share/javascript/">
-
Nathan C almost 11 yearsWhat does the server log say? It should say where it's looking.
-
Pete almost 11 yearsIt's looking in /usr/share/javascript/search.js
-
Pete almost 11 yearsWhat would cause the files from /javascript/ to be searched for there? Would it be an .htaccess or vhost.conf setting somewhere? I've not set up anything like that intentionally, but this is old legacy code that I've taken over
-
ThatGraemeGuy almost 11 yearsInclude the vhost config in your question.
-
Nathan C almost 11 yearsThere has to be some weird vhost config that's causing the issue.
/usr/share/
is common for some "installable" applications (webmin is one). -
Pete almost 11 yearsI've run
grep -iR javascript ./
in the /etc/apache2 folder, and found a few entries, I'll update the question -
Pete almost 11 yearsI generally use /js/ for my Javascript so this has never been a problem before. Am I safe to just delete those rules and restart apache?
-
Jenny D almost 11 yearsIt seems to be the config in conf.d/javascript-common.conf that's the problem. I'd move that file to e.g. /tmp for the moment and restart apache to see if that will a) fix it and b) not break anything else.
-
Pete almost 11 yearsThat solved it. Someone needs to propose an actual answer so I can accept it
-
-
Anurag Prashant about 4 yearsThis is perfectly worked for me. :) Thank you so much @sumit