skip to Main Content

One of the Joomla 3 templates I use on a multilingual website generates wrong href tag links in the HTML header and also in the body. The href on all multilingual pages reads:

in the HEAD
    link href="https://domain/page?layout=post" rel="alternate" hreflang="en-GB" />

in the BODY
    a href="/fr/page?layout=post">                                              

and should be


    link href="https://domain/page" rel="alternate" hreflang="en-GB" />
and
    a href="/fr/page">      

I have currently used a temporary rewrite of the .htaccess file; however, that generated hundreds of 301 redirects and I am sure that is not a good SEO solution.

Because it will take some time for finding the origin and permanently correcting the code, I need some help with PHP to remove the string ?layout=post and showing the correct href links in the and .

2

Answers


  1. My guess is you need to go to Joomla settings and enable Search Engine Friendly URLs

    And only after this you should modify .htaccess file.

    Example of Joomla settings change

    This should solve your problem, if it didn’t that it is maybe as you say a template issue but then you have to look it in a template files witch take some time from you.

    Login or Signup to reply.
  2. this is the version I’m using.
    I make it on clean php.

        <?php
    // your full url
    $url = 'https://www.shop.com/en/category/tv-video-and-audio/';
    //accepted languages or site version
    $langs = array(
            'en',
            'cn',
            'ru'
        );
        //function to render full page link in all languages
    function renderhrefurl($url = NULL, $lang = NULL){
        $exploded = explode('/', $url);
        $exploded[3] = $lang;
        return implode('/', $exploded);
    }
    //set hreflang attribute data
    $hreflangs = array(
        array(
            'hreflang' => 'en',
            'hrefurl' => renderhrefurl($url, 'en')
            ),
        array(
            'hreflang' => 'cn',
            'hrefurl' => renderhrefurl($url, 'cn')
            )
            ,
        array(
            'hreflang' => 'ru',
            'hrefurl' => renderhrefurl($url, 'ru')
            )
        );
        //generate result
        foreach($hreflangs as $key => $item){
            echo '
            Key: '.$key.' - lang: '.$item['hreflang'].' = '.$item['hrefurl'];
        }
        echo '
        ------- Rendered Href Langs Tags ------- ';
        //generate completed hreflangs
            foreach($hreflangs as $key => $item){
            echo '
            <link rel="alternate" hreflang="'.$item['hreflang'].'" href="'.$item['hrefurl'].'" />';
        }
        
        ?>
    

    Copy this code and paste to php compiler online to show how it work.
    And use strtok('Your link with get parameter', '?'); to delete get parameters!

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search