Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sitemap not loading stylesheet on sub paths #88

Open
brandsis opened this issue Mar 20, 2024 · 21 comments
Open

Sitemap not loading stylesheet on sub paths #88

brandsis opened this issue Mar 20, 2024 · 21 comments
Labels
type: bug 🐛 Is a bug; fixes a bug
Milestone

Comments

@brandsis
Copy link

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.

@tobimori
Copy link
Owner

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

@tobimori
Copy link
Owner

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

@tobimori tobimori added the needs: information ❓ Requires more information to proceed label Mar 20, 2024
@brandsis
Copy link
Author

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

@tobimori
Copy link
Owner

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 tobimori added type: bug 🐛 Is a bug; fixes a bug and removed needs: information ❓ Requires more information to proceed labels Mar 21, 2024
@tobimori
Copy link
Owner

tobimori commented Mar 21, 2024

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") . '"'));

?

@brandsis
Copy link
Author

brandsis commented Mar 21, 2024

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.

@tobimori
Copy link
Owner

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?

@brandsis
Copy link
Author

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

@brandsis
Copy link
Author

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. 🙂

@tobimori
Copy link
Owner

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
Copy link
Owner

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 tobimori changed the title Sitemap not generating Sitemap not loading stylesheet on sub paths Mar 24, 2024
@brandsis
Copy link
Author

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
Copy link
Author

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

@tobimori
Copy link
Owner

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.

@brandsis
Copy link
Author

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

image

@tobimori
Copy link
Owner

Have you cleared OP Cache?

@brandsis
Copy link
Author

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?

@tobimori
Copy link
Owner

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

@brandsis
Copy link
Author

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.

@nilshoerrmann
Copy link

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.

@Jobbies
Copy link

Jobbies commented Oct 21, 2024

I am also having the same problem. Could this be from the routes.php?

	[
		'pattern' => 'sitemap',
		'action' => function () {
			if (!option('tobimori.seo.sitemap.redirect', true) || !option('tobimori.seo.sitemap.active', true)) {
				$this->next();
			}

			go('/sitemap.xml');
		}
	],

Should the Route be dynamic to the site?

go(site()->url() . '/sitemap.xml');

@tobimori tobimori added this to the 2.0.0 milestone Oct 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug 🐛 Is a bug; fixes a bug
Projects
None yet
Development

No branches or pull requests

4 participants