Ubuntu Linux Apache2 javascript folder ‘404 file not found’ error? I’ve got the fix!

I’ve had the unexpected privilege of transferring some a web application over from a CentOS Plesk/HTTPD server environment over to an Ubuntu Apache2 VPS server. The web application contained your standard CSS, images and javascript folders.

However the most puzzling thing occurred where when I configured Apache2 to run the web application, the /javascript folder could not be read even though it was physically there and in the right place. After spending two hours attempting to remove .htaccess directives, modifying CHOWN/CHMOD permissions and double checking the Apache vhost.conf file, it came down to a .conf file configured in the default Apache2 setup that was rewriting the ‘Alias’ path of any folders beginning with /javascript.

To fix this, you will need to perform the following:

  1. Type vi /etc/apache2/conf.d/javascript-common
  2. Comment out the following line: Alias /javascript /usr/share/javascript/
  3. Save and restart Apache2 by typing /etc/init.d/apache2 restart

You may choose to rename or change the entry in point #2 above depending on whether you are sharing a javascript library across your whole Apache2 setup. Let me know if this worked for you.

Comments (16)

  • Ket says:

    That sorted the problem .. what a weird thing to do.

    Been toying with that javascript bug for a while now. Cheers.

  • James says:

    Thanks for that. Ive been searching through my ispconfig amongst other things, including google for the last hour or so. Started to get frustrated until I ran into this.

    Much appreciated you saved me a lot of time. I cant believe they included that.

  • Alison says:

    Oh my gosh, I’ve been playing with my config files for 3 hours trying to figure that one out! Thanks!

  • Justin says:

    Thanks heaps for posting. That had me baffled for awhile.

  • Arne says:

    Thanks! Worked for me! 🙂

  • Chad says:

    you saved my life. my eyes were about to pop out of my head

  • ephraim says:

    Thanks, that saved me. Weird that it worked for me before, but stopped when I installed php.

  • Ram says:

    That was a saviour stuff – such a freaky error!

  • Dave says:

    Thanks – that would’ve been a tough one to figure out without this! I probably would’ve just ended up renaming the folder to ‘js’ or something 😛 Glad I didn’t have to resort to that.

  • Carlos Egea » Blog Archive » Error 404 al intentar ejecutar Javascript en servidor Apache says:

    […] En esta ocasión en un servidor recién instalado los permisos eran correctos. La solución la he encontrado muy bien explicada en este post:  Ubuntu Linux Apache2 javascript folder ’404 file not found’ error? I’ve got the fix! […]

  • Przemek says:

    I spent whole evening fighting with this. Thanks! 🙂

  • Touc says:

    Thans a lot man!

    This was insane! Oo

  • Brett Thorson says:

    That worked for me. Thanks. I thought it was something with mime types and JS, so was fixating the search on JS. Thanks for the redirect.

  • Pranav Kapoor says:

    THANKS A TON.

    Can’t believe these defaults. It was impossible to debug.

  • robert says:

    Anyone have any clue what causes this garbage to happen? I had a site working 100% perfectly fine on my test server running Ubuntu 14.04, the computer magically restarted itself as I walked up to it after getting something to eat. When it started back up my javascript files were all magically 404 It makes me want to punch the monitor when this idiot shit happens. I am wondering if there was some sort of update while I walked away.

    This makes no sense.

  • robert says:

    Also for Ubuntu 14.04Lts the file you need to change as above is now /etc/apache2/conf-enabled/javascript-common.conf
    I commented out that one line, restarted Apache and BAM reversed stupid magic.

  • Leave a Reply

    Your email address will not be published. Required fields are marked *

    This site uses Akismet to reduce spam. Learn how your comment data is processed.