sitemap.xml с и без www

6

Здравствуйте все.
Странную вещь обнаружил. Если смотрю на https://www.example.com/xml/sitemap.xml то всё нормально.
А если без www смотрю на https://example.com/xml/sitemap.xml то вижу ошибку стилей:


Ошибка загрузки таблицы стилей: Произошла неизвестная ошибка (805303f4)
https://www.example.com/theme/_common/sitemap.xsl


Гугл говорит что исправить можно в .htaccess.
Как именно правильно это написать для Ваки?

Comments

  1. Re: sitemap.xml с и без www

    Cause:
    • Referrer-Policy: strict-origin-when-cross-origin violation
    • sitemap.xml:2 Unsafe attempt to load URL https://www.example.com/theme/_common/sitemap.xsl from frame with URL https://example.com/xml/sitemap.xml. Domains, protocols and ports must match.
      sitemap.xml:1 [Deprecation] crbug.com/435623334: This page uses XSLT, which being considered for removal from the web. If that happens, it is possible that this page will need to be updated to maintain functionality.	
    • In other words https://www.example.com won't load https://example.com links or vice versa with strict-origin-when-cross-origin policy in place, Security Header issue that affects CSP and Referrer-Policy.

    Solution:
    • ease Referrer-Policy in Admin panel (probably not a good idea)
    • change URL for sitemap.xsl to /theme/_common/sitemap.xsl
      • <?xml-stylesheet type="text/xsl" href="/theme/_common/sitemap.xsl"?>	
      • diff --git a/src/class/feed.php b/src/class/feed.php
        index 39add03..a7f9f1f 100644
        --- a/src/class/feed.php
        +++ b/src/class/feed.php
        @@ -311,7 +311,7 @@
                 $xml  = '<?xml version="1.0" encoding="utf-8"?>' . "\n";
                 $xml .= $this->engine->db->xml_sitemap_gz
                         ? ''
        -                : '<?xml-stylesheet type="text/xsl" href="' . $this->engine->db->base_url . Ut::join_path(THEME_DIR, '_common/sitemap.xsl') . '"?>' . "\n";
        +                : '<?xml-stylesheet type="text/xsl" href="' . $this->engine->db->base_path . Ut::join_path(THEME_DIR, '_common/sitemap.xsl') . '"?>' . "\n";
                 $xml .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . "\n";
         
                 if ($pages)
      • Does this work, can I merge?

    To make matters worse, I have my own redirect zoo in root mainly to redirect www. and legacy locations.
    There are similar issues with canonical URLs on regarding the www. prefix.

    To completely disable the www prefix in URLs on an Apache server, you must configure a redirect from www.example.com to example.com using either .htaccess or the Apache virtual host configuration.
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
    RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L]	


    Despite this server-side redirection, the PHP $_SERVER['SERVER_NAME'] variable may still reflect the www. prefix if the server configuration or the request's initial host header is not properly normalized. This is because $_SERVER['SERVER_NAME'] is derived from the HTTP request headers and may not be updated by the rewrite rule if the server does not re-evaluate the host header after the redirect.

    $this->config['base_path']	= $this->get_base_url($this->canonical);	


    So in the current configuration if you chose to use www. prefix redirect disable $this->canonical URLs.
    Perhaps it is useful the add an option in the get_base_url() function in the Settings class that removes the www. prefix from the $base_url. Is there another way to address this www. prefix alias mess?

    • base_url
    • base_path
    • WikiAdmin
    • 11/27/2025 17:21 edited
  2. Ответ: sitemap.xml с и без www

    заменил как указано в 
    diff --git a/src/class/feed.php b/src/class/feed.php
    теперь нормально в обоих вариантах.
    Спасибо WikiAdmin!
  3. Ответ: sitemap.xml с и без www

    Кстати, когда смотрел файл class/feed.php увидел возле 46 строки:
    $link ??= $this->engine->db->base_url;

    надпись Syntax error, unexpected ' = '
  4. Ответ: sitemap.xml с и без www

    И ещё, в админке – Синхронизация базы данных – нажимаю синхрониззировать, вверху показывает Новая версия карты сайта создана успешно.
    а возле кнопки всегда:
    Период, дней: 0. Последний раз записано 1970–01–01 00:00:01.
  5. Re: sitemap.xml с и без www

    The ??= operator in PHP is known as the null coalescing assignment operator. It was introduced in PHP 7.0 as a shorthand way to assign a value to a variable only if that variable is currently null.

    What causes the error?
    • WikiAdmin
    • 11/27/2025 19:05 edited
  6. Re: sitemap.xml с и без www

    Currently it does not set the timestamp for xml_sitemap_time >= 0, because the time is not required, but we can set it there too.

    <?php
    
    if (($days = $this->db->xml_sitemap_time) <= 0)
    {
        // write
    }
    else if (time() > @$this->db->maint_last_xml_sitemap)
    {
        $this->db->set('xml_sitemap_update', 0, false);
        $this->db->set('maint_last_xml_sitemap', time() + $days * DAYSECS);
    }
    else
    {
        $this->db->set('xml_sitemap_update', 1);
        return;
    }
Log in or create an account to post a comment.