I found a small bug in the URL check function. It leads to a wrong url creation whenever there is already a "?" char in the URL (the URL has already get params).
if (strpos('?', $url))
if (strpos($url, '?'))
Then it is working correctly ;-)