Joomla website adding main url behind external url

Sometime we face this problem on few joomla websites.

You are trying to add a url but your main website url is addding up in the target link on its own.

Sometimes all the links also add this.

This small trick is basically base href feature supported by all browsers.

This basically setup a standard global url for all the links originating on the websites. external urls linking to other websites don’t get affected but sometime it does add up because of some configuration with the server running your joomla website.

To solve we can probably use these two lines as the most basic option here. At-least this is what I use to do most of the time.
$doc = JFactory::getDocument();
unset($doc->base);