Example user input
http://domain.com/ http://domain.com/topic/ http://domain.com/topic/cars/ http://www.domain.com/topic/questions/
I want
You could use the parse url Functionality of PHP. This will work for all Protocols, even ftp:// or https://
Eiter get the Protocol Component and substr it from the Url, or just concatenate the other Parts back together ...
http://php.net/manual/de/function.parse-url.php