Rebased

This should gracefully handle the case where HTTP_HOST or HTTP_REFERER headers are not present