1

When I am in home page, everything is OK. All images and assets are loaded since relative URL works. But when I visit an internal page, such as:

example.com/terms

The images' links break, since I have turned on SEF links, and as long as the links are generated in "relative style", the links do not work. Since, for example in an image (generated by Language Switched Module), the src attribute is:

"/images/flags/en.png"

I need the above URL to be generated absolutely.

2 Answers 2

3

Make sure the System - SEF plugin is published. This plugin contains the following code, which should be adding the correct URL path to images before the page is rendered:

// Replace src links.
$base   = JUri::base(true) . '/';
$buffer = $this->app->getBody();

// Replace index.php URI by SEF URI.
if (strpos($buffer, 'href="index.php?') !== false)
{
    preg_match_all('#href="index.php\?([^"]+)"#m', $buffer, $matches);
    foreach ($matches[1] as $urlQueryString)
    {
        $buffer = str_replace('href="index.php?' . $urlQueryString . '"', 'href="' . JRoute::_('index.php?' . $urlQueryString) . '"', $buffer);
    }
    $this->checkBuffer($buffer);
}

// Check for all unknown protocals (a protocol must contain at least one alpahnumeric character followed by a ":").
$protocols = '[a-zA-Z0-9\-]+:';
$attributes = array('href=', 'src=', 'poster=');
foreach ($attributes as $attribute)
{
    if (strpos($buffer, $attribute) !== false)
    {
        $regex  = '#\s+' . $attribute . '"(?!/|' . $protocols . '|\#|\')([^"]*)"#m';
        $buffer = preg_replace($regex, ' ' . $attribute . '"' . $base . '$1"', $buffer);
        $this->checkBuffer($buffer);
    }
}

In this case, the true in the JUri::base(true) means that it is the path that is being generated rather than the full URL. You could get an absolute link by removing the "true", but note that in practise you should never edit core files, so this would require a new plug-in to be done properly. Also, the base path and absolute URL should both work so even if this fixed the issue, the actual cause of your problem is most likely elsewhere.

Your example /images/flags/en.png actually makes it look like this plugin is working correctly, since that / at the beginning (assuming your site is in the root of your domain) means it will be loading the image from the root rather than relative to the page you are on, as it should. In your database, the image will most likely be saved at images/flags/en.png.

Does this image actually exist at http://www.yourdomain.com/images/flags/en.png ? If not, where does the image load from when SEF is turned off?

0
2

If your image appears in HTML body like that

<img src="images/image.png">

at front-end then keep in mind that URL are related to your base url, wich is added as base meta tag in your page

<head>

and in Joomla sometimes it not properly generated

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.