kirby-seo icon indicating copy to clipboard operation
kirby-seo copied to clipboard

Sitemap not loading stylesheet on sub paths

Open brandsis opened this issue 1 year ago • 28 comments

Hi, Tobias. I've installed v1.0.0 but I'm still not getting a sitemap to generate. I've added the blueprint tabs and meta snippets, and I've set the Robots Directives for each page in the Panel. /robots.txt is working fine but there is nothing showing at /sitemap.xml – it's a blank page with only xml-stylesheet in the Dev Tools Elements.

What am I missing?

This is what's in my config.php file...

	'tobimori.seo' => [
		'canonicalBase' => 'http://localhost/projects/brandsistency',
		'lang' => 'en_GB',
		'robots' => [
			'active' => true,
			'content' => [
				'*' => [
					'Allow' => ['/'],
					'Disallow' => ['/kirby', '/panel', '/content']
				]
			],
			'sitemap' => 'http://localhost/projects/brandsistency/sitemap.xml'
		],
		'sitemap' => [
			'active' => true,
			'excludeTemplates' => ['tertiary', 'maintenance']
		]
	],

Thanks.

brandsis avatar Mar 20 '24 20:03 brandsis

What's the output of viewsource:http://localhost/projects/brandsistency/sitemap.xml?

tobimori avatar Mar 20 '24 20:03 tobimori

Besides that, it shouldn't be necessary specify robots.active, sitemap.active & robots.sitemap.

tobimori avatar Mar 20 '24 20:03 tobimori

What's the output of viewsource:http://localhost/projects/brandsistency/sitemap.xml?

There is no output, just a blank page. If I right-click, there is no context menu. In Dev Tools, the Elements section contains only xml-stylesheet and the Console has the error GET http://localhost/sitemap.xsl net::ERR_ABORTED 404 (Not Found).

From that, I tried /sitemap.xsl and there is a styled page there but the sitemap is empty...

image

brandsis avatar Mar 20 '24 23:03 brandsis

It seems like the issue is that Chrome is trying to get the sitemap stylesheet from http://localhost/sitemap.xsl but your project is in a subfolder, so it's located at http://localhost/projects/brandsistency/sitemap.xsl instead.

tobimori avatar Mar 21 '24 08:03 tobimori

Can you try changing this line https://github.com/tobimori/kirby-seo/blob/main/classes/Sitemap/SitemapIndex.php#L44C1-L45C112 to

$doc->appendChild($doc->createProcessingInstruction('xml-stylesheet', 'type="text/xsl" href="' . App::instance()->site()->canonicalFor("sitemap.xsl") . '"'));

?

tobimori avatar Mar 21 '24 08:03 tobimori

No change.

I updated line 45 in the file http://localhost/projects/brandsistency/site/plugins/seo/classes/Sitemap/SitemapIndex.php, cleared cache in the Panel and the browser, did a hard reload and the result was the same – still no /sitemap.xml output and the same error message in the Console. I also tried heard coding the full href URL in that line and again no change.

brandsis avatar Mar 21 '24 13:03 brandsis

hm, that's weird

some other things to consider:

  • does it happen with a new plainkit locally?
  • does it work in a different browser?
  • does it happen without the subpath?
  • does it happen on a production server with a subpath?

tobimori avatar Mar 21 '24 18:03 tobimori

Tobias, it will take me a little while to answer all those questions. I'll get back to you soon.

brandsis avatar Mar 22 '24 09:03 brandsis

Hi, Tobias.

I haven't tried a fresh plainkit install but I can answer the other questions.

  • does it work in a different browser?

I get the same result in most other browsers. In Firefox Developer Edition, there is a different result, albeit not a successful one. If I go to localhost/projects/brandsistency/sitemap.xsl, it downloads the file rather than displaying on screen. And if I go to localhost/projects/brandsistency/sitemap.xml, instead of a completely blank page, I see this...

image

It still seems to be looking in the root for the .xsl file, despite that update to line 45 in SitemapIndex.php.

  • does it happen on a production server with a subpath?

Yes. I promoted the changes to my test site (brandsistency.dev/brandsistency), which is public-facing site but also in a subfolder, and the results were the same. brandsistency.dev/brandsistency/sitemap.xml is blank, or in Firefox Dev Ed gives a similar screen looking for the .xsl file in the location https://brandsistency.dev/sitemap.xsl – i.e. in the root again not in the subfolder.

  • does it happen without the subpath?

No. I also promoted the updates to my live site (brandsistency.com), which is both public-facing and located at the domain root. Everything is working fine there. brandsistency.com/sitemap.xml looks as expected...

image

So, as you thought, it's only an issue with subfolder sites.

Not a massive deal as it's working in production, but it would be good to have it working in subfolder sites. That's so clients can be reassured that the sitemap is working when looking at a test site before going to production. 🙂

brandsis avatar Mar 24 '24 16:03 brandsis

Thank you very much. It seems like it's indeed an issue with the stylesheet, so it should not prevent indexing by crawlers even on a subpath in production.

If you open view-source:https://brandsistency.dev/brandsistency/sitemap.xml in your Chrome, you'll see the source code as expected.

tobimori avatar Mar 24 '24 16:03 tobimori

What's confusing for me is that you said even with changing the <?xml-stylesheet type="text/xsl" href="/sitemap.xsl"?> manually to the absolute url, e.g.https://brandsistency.dev/brandsistency/sitemap.xsl it's not working for you?

tobimori avatar Mar 24 '24 16:03 tobimori

What's confusing for me is that you said even with changing the <?xml-stylesheet type="text/xsl" href="/sitemap.xsl"?> manually to the absolute url, e.g.https://brandsistency.dev/brandsistency/sitemap.xsl it's not working for you?

I didn't actually try hard-coding the URL in the test (.dev) environment – only in localhost. I'll try that later today.

brandsis avatar Mar 25 '24 09:03 brandsis

Tobias, I have tried hard-coding the stylesheet location in SitemapIndex.php. Line 45 now reads...

$doc->appendChild($doc->createProcessingInstruction('xml-stylesheet', 'type="text/xsl" href="https://brandsistency.dev/brandsistency/sitemap.xsl"'));

I've cleared cache in the Panel and the browser and there is no change...

  • https://brandsistency.dev/brandsistency/sitemap.xml is blank with only "xml-stylesheet" showing in Dev Tools
  • view-source:https://brandsistency.dev/brandsistency/sitemap.xml does still contain the sitemap content
  • https://brandsistency.dev/brandsistency/sitemap.xml is the styled but empty view

brandsis avatar Mar 26 '24 08:03 brandsis

CleanShot 2024-03-26 at 10 01 10@2x

Was the change made on the URL you linked or did you remove it again? It shows the /sitemap.xsl without the full path here.

tobimori avatar Mar 26 '24 09:03 tobimori

No, I didn't remove it again. This is Line 45 right now, viewed through cPanel...

image

brandsis avatar Mar 26 '24 09:03 brandsis

Have you cleared OP Cache?

tobimori avatar Mar 26 '24 09:03 tobimori

No, I haven't. The only way I'm aware of is to create a file called flush_cache.php with the code...

<?php
opcache_reset();
?>

...to upload that to the site root and then call it via the browser. I did that but https://brandsistency.dev/brandsistency/flush_cache.php returns an error and when I visit the sitemap it is still blank.

Any other suggestions on how I can clear OPcache?

brandsis avatar Mar 26 '24 09:03 brandsis

Except for Kirby Pages cache and OPcache - no idea where else it should be cached.

tobimori avatar Mar 26 '24 10:03 tobimori

Tobias, I found out that the "opcache" extension wasn't enabled in my hosting account's PHP config. I have now enabled it but the flush_cache.php script only seems to work from my account root. I called the file from that location and did not get the error message, so I'm assuming it works. Not sure how I check, though.

Calling that file/script from any of my 'add-on' domains, such as brandsistency.dev, does still throw the error. But I am told by my host (Namecheap) that flushing from the account root should work for all domains in my account.

Anyway, I have cleared Panel and browser cache again and tried accessing https://brandsistency.dev/brandsistency/sitemap.xml but it is still blank. The href in the source still does not show the full path.

brandsis avatar Mar 26 '24 13:03 brandsis

What's confusing for me is that you said even with changing the <?xml-stylesheet type="text/xsl" href="/sitemap.xsl"?> manually to the absolute url, e.g.https://brandsistency.dev/brandsistency/sitemap.xsl it's not working for you?

Hardcoding the path – not the full URL – works for me.

nilshoerrmann avatar Jul 03 '24 06:07 nilshoerrmann