improve self-url discovery

(use ports if not standard, use other vars for scheme, move / around as needed)
Not required indeed but recommended by PSR-2 :smile: (Yes I know I'm a bit inflexible with coding style…)

You could check your changes against [phpcs](http://pear.php.net/manual/en/package.php.php-codesniffer.php), it'll warn you about thoses.