Created
September 13, 2012 02:14
-
-
Save there4/3711416 to your computer and use it in GitHub Desktop.
404 Handler for JS Files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// # 404 Handler for JS in Dev Environment | |
// | |
// I kept stubbing my toe. Backbone can make it hard to notice that a file | |
// has returned a 404 unless you have the console open. This makes it much | |
// more noticeable. | |
// | |
// This is coupled with the .htaccess file entry: | |
// | |
// RewriteCond %{REQUEST_FILENAME} !-f | |
// RewriteRule ^(.*)\.js$ /404js.php [L] | |
// | |
// Write to the error log so that it apache knows what happened and we can | |
// continue to tail the logs/error_log | |
error_log( | |
'File does not exist: ' . $_SERVER["REQUEST_URI"] . | |
', referer: ' . $_SERVER["HTTP_REFERER"], | |
4 | |
); | |
// Tell the browser what happened, and that we're sending out JS | |
header("Status: 404 Not Found"); | |
header("Content-type: text/javascript"); | |
// Show the user what's up. | |
?> | |
alert( | |
"4 0 4 J S E R R O R\n" + | |
"=============================\n" + | |
"<?php echo htmlspecialchars($_SERVER["REQUEST_URI"]); ?> was not found." | |
); | |
<?php | |
/* End of file 404js.php */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment