Properly escape backslashes.  Fixes #1962.
Use SERVER_NAME instead of HTTP_HOST.  Fixes #1963.