You are using rawurlencode which has RFC3986-exceptions on its own: `-_.~`. http://php.net/manual/en/function.rawurlencode.php