Viewing 2 replies - 1 through 2 (of 2 total)
  • Sa?a

    (@stodorovic)

    I think that isn’t good to submit both sitemaps (www and non-www) because both sitemaps contain identical URLs. Also, WP (by default) redirects URLs to canonical URL (variant which is set in Settings/General – Site Address).

    From other side, both XML sitemaps are valid. Only issue is stylesheet which browsers load to show nice output. You could use this code (it works in both cases):

    add_filter( 'wpseo_stylesheet_url', function( $stylesheet ) {
            if ( ! empty( $_SERVER['HTTP_HOST'] ) ) {
                    $proto = is_ssl() ? 'https://' : 'https://';
    
                    return preg_replace( '#(//[a-zA-Z0-9-.]+)#', $proto . $_SERVER['HTTP_HOST'], $stylesheet, 1 );
            } else {
                    return $stylesheet;
            }
    } );
    

    PS: I’ve tested it with latest version of Yoast SEO and WP Super Cache. It works (please clear cache after you add PHP code).

    Thread Starter zviera

    (@zviera)

    Hi Sa?a,

    thanks for the quick reply and the code. It works!

    About submitting identical sitemaps – I have actually never fully understook why Google Search Console recommends creating accounts for both www and non-www versions of the site website, and also for both https:// and https:// versions. So you are saying I should create those account, but submit only one sitemap?

    “Also, WP (by default) redirects URLs to canonical URL” – Yeah, I know this, that’s why I was surprised the redirect doesn’t happen with the sitemaps.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Sitemap empty on www url version (Unsafe attempt to load URL error)’ is closed to new replies.