Refactoring of HTTP_REFERER handling
Fix issue with wrong permissions on js/index.php