I generate a link in a module as follows:

$user->contactAddress = str_replace("//", "/", trim(JUri::base() . $params->get('defaultContactAddress') . '?' . $params->get('parameterName') . '=' . $user->cfid));


JUri::base() is https://mydomain.tld/devel/j4/
$params->get('defaultContactAddress') is "direktkontakt"
$params->get('parameterName') is "cfid"
$user->cfid is 99

The link is properly generated, echo $user->contactAddress; gives https:/mydomain.tld/devel/j4/direktkontakt?cfid=99.

The following is way unexpected:

<a href="<?=$user->contactAddress;?>"><?=$user->contactAddress;?></a>

results in

<a href="https:/mydomain.tld/devel/j4/direktkontakt?cfid=99">https:/mydomain.tld/devel/j4/direktkontakt?cfid=99</a>

BUT all tested browsers (Edge, Firefox, Chrome) point to


Has anyone any ideas why?

1 Answer 1


The str_replace() call breaks the URL by changing https://mydomain.tld to https:/mydomain.tld. The code can be changed in many ways, depending on your use case. You may add validation to defaultContactAddress field to prevent users adding a leading slash in the first place. Or you may trim the leading slash from the value and not from the whole URL:

ltrim($params->get('defaultContactAddress'), '/')

On HTML pages it's generally not necessary to include absolute URLs. So you can use JUri::base(true) to get just the path of your Joomla root which would also avoid the issue.

  • Perfect, thank you! I didn't see the second slash after https was missing.
    – alve89
    Mar 14 at 10:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.