Not very good with plugin, but should I put the hook as global_start? Also how would the php code look, pseudocode is fine, just want to get an idea on how to do this.
You have to check that the URL is not already in the correct format - see the PHP server environment variables. Also, you do not need that conditional, you are already running the plugin only in member.php.