Results 1 to 4 of 4

Thread: Contao Sitemap generates url for same page twice

  1. #1
    New user
    Join Date
    09-13-17.
    Posts
    26

    Default Contao Sitemap generates url for same page twice

    I am using contao 4.4 instance.I have a problem in google sitemap generation. I have a newsletter page (page type = regular ) . In that page I have some newsletter articles (with teaser) . When I generate the sitemap, the url of these articles generated twice. When I checked the core I found a class which creates the page array for generating sitemap

    vendor/contao/core-bundle/src/Resources/contao/classes/Backend.php
    line no 662 - 680 .


    Which append 'articles/' to the articles with teaser. So the sitemap generates url

    1. with articles/
    2. without articles/



    The first one is the correct url.Second Url generate 404. How I fix the issue ?

  2. #2
    User Spooky's Avatar
    Join Date
    01-03-13.
    Posts
    331

    Default

    I don't quite understand your setup. Are you talking about article teasers or newsletters? Can the issue be reproduced on demo.contao.org/contao?

  3. #3
    New user
    Join Date
    09-13-17.
    Posts
    26

    Default

    My siteconfiguration is as follows

    • created a regular page with hidden in navigation and created articles with configuration show teaser
    • created another page and created elements as 'teaser articles' and select articles from the above page

  4. #4
    New user
    Join Date
    09-13-17.
    Posts
    26

    Default

    I resolved the issue.
    The url's were regenerated from the newsletter-bundle. In core bundle, the url of the article with teaser is generated. The newsletter-bundle is also contain hook for creating searchable page array. The hook regenerates the url. I wrote a function in vendor/contao/newsletter-bundle/src/Resources/contao/classes/Newsletter.php to check whether the array contain any duplicate url.


    Modified function getSearchablePages() ( line 889-897
    )

    Code:
    if($this->checkValidUrl($arrPages, $objItem, $strUrl)){
                $arrPages[] = sprintf($strUrl, ($objItem->alias ?: $objItem->id));
    }

    Defining new function for finding duplicate

    Code:
    public function checkValidUrl($arrPages, $objItem, $strUrl)
        {
            $alias      = $objItem->alias ?: $objItem->id;
            $urlExplode = explode('%s', $strUrl);
            $articleUrl = $urlExplode[0] . 'articles';
            foreach ($arrPages as $arrPage) {
                $validarticleUrl = $articleUrl . '/' . $alias;
                if (strcasecmp($arrPage,$validarticleUrl) == 0) {
                    return false;
                }
            }
            return true;
        }
    Last edited by aswathy; 03/23/2018 at 07:57.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •