You should add ."/" after $_SERVER['SERVER_NAME'] because it is also possible to do a redirect like this:
https://www.ubbcentral.com/forums/ubbthreads.php?ubb=changeprefs&what=style&value=1&curl=//www.ubbcentral.com@ubbdev.com