sitemaps: absolute URL for sitemaps
authorIan Marlier <imarlier@wikimedia.org>
Wed, 29 Aug 2018 18:02:23 +0000 (14:02 -0400)
committerIan Marlier <imarlier@wikimedia.org>
Wed, 29 Aug 2018 20:08:17 +0000 (16:08 -0400)
Google, at least, considers sitemap indexes that provide relative URLs
as being broken.

Bug: T202321
Change-Id: I5509be4b165eea9eca36e3f4975f87285ef87911

maintenance/generateSitemap.php

index 70fdebf..dc1de4f 100644 (file)
@@ -485,7 +485,9 @@ class GenerateSitemap extends Maintenance {
         */
        function indexEntry( $filename ) {
                return "\t<sitemap>\n" .
-                       "\t\t<loc>{$this->urlpath}$filename</loc>\n" .
+                       "\t\t<loc>" . wfGetServerUrl( PROTO_CANONICAL ) .
+                               ( substr( $this->urlpath, 0, 1 ) === "/" ? "" : "/" ) .
+                               "{$this->urlpath}$filename</loc>\n" .
                        "\t\t<lastmod>{$this->timestamp}</lastmod>\n" .
                        "\t</sitemap>\n";
        }