If Apache2 won’t serve your JavaScript file try…

I had an issue with Apache2 improperly serving a JavaScript file which I seem to have fixed by making sure the file was terminated with a new-line character… this was really hard to diagnose and resolve! The behaviour in Firefox was that the file just didn’t finish to download, whereas the Apache2 logs indicated a 200 result… I think it may have had something to do with automatic compression, which is a dark art that I do not understand (mumbles something about mod deflate…).

Apache2 REQUEST_FILENAME requires DOCUMENT_ROOT

I had a problem with my rewrite rules, that looked like this:

  DocumentRoot /var/www/trust.jj5.net
  RewriteEngine On
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule (.*) http://trust.jj5.net/sorry.html [L,R]

I was trying to redirect any request which didn’t match a file or directory. The !-f and !-d requirements were failing because the path to the REQUEST_FILENAME wasn’t fully qualified. I fixed the problem by including the DOCUMENT_ROOT:

  DocumentRoot /var/www/trust.jj5.net
  RewriteEngine On
  RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
  RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d
  RewriteRule (.*) http://trust.jj5.net/sorry.html [L,R]

Happy days! :)